Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Transfers, Addressing, and Arithmetic

Similar presentations


Presentation on theme: "Data Transfers, Addressing, and Arithmetic"— Presentation transcript:

1 Data Transfers, Addressing, and Arithmetic
Lecture 6

2 Data Transfer Instructions
Operand Types Three basic types of operands: *Immediate: a constant integer (8, 16, or 32 bits) -value is encoded within the instruction ƒ *Register: the name of a register -register name is converted to a number and encoded within the instruction *Memory: reference to a location in memory memory address is encoded within the instruction, or a register holds the address of a memory location

3 Direct Memory Operands
-A direct memory operand is a named reference to storage in memory -The named reference (label) is automatically dereferenced by the assembler. The brackets imply a deference operation .Data Var1 byte 10h .code Mov al, var1 Mov al, [var1]

4 MOV Instruction *MOV Instruction
Move (copy) from source to destination *Syntax: MOV destination, source -destination operand’s contents change source operand’s contents do not change -Both operands must be the same size -Both operands cannot be memory operands -CS, EIP, and IP cannot be the destination -No immediate to segment moves

5 Here is a list of the general variants of MOV, excluding segment registers:
-MOV reg, reg -MOV mem, reg -MOV reg, mem -MOV mem, imm -MOV reg, imm

6 Examples: .data count BYTE 100 wVal WORD 2 .code mov bl,count mov ax,wVal mov count,al mov al,wVal ; error, AL is 8 bits mov ax,count ; error, AX is 16 bits mov eax,count ; error, EAX is 32 bits

7 Arithmetic Instructions – Processing Binary Data
Description ADC Add with carry IDIV Divide signed ADD Add IMUL Multiply signed CBW Convert byte to word MUL Multiply unsigned CDQ Convert doubleword to quadword NEG Negate CWD Convert word to doubleword SBB Subtract with borrow CWDE Convert word to extended doubleword SUB Subtract DIV Divide unsigned

8 XCHG Instruction XCHG Instruction exchanges the values of two operand.
At least one operand must be a register – -No immediate operands are permitted

9 example

10 INC and DEC Instructions
-Add 1, subtract 1 from destination operand, operand may be register or memory . INC destination : Logic: destination ← destination + 1 DEC destination: Logic: destination ← destination – 1

11 Example:

12 ADD Instruction ADD Instruction ADD destination, source:
Logic: destination ← destination + source

13 Example:

14 SUB Instruction SUB Instructions o SUB destination, source
Logic: destination ← destination – source

15 example

16 7.3.1 Addition and Subtraction Of Binary Data
Format for ADD and SUB instructions: (note: there are no direct memory-to-memory operations)

17 NEG Instruction NEG (negate) Instruction
-Reverses the sign of an operand - Operand can be a register or memory operand

18 example

19 • Implementing Arithmetic Expressions

20 Exercise Assume that BYTE1 is defined as DB 05, show the result for the following instructions:

21 Indirect Addressing -An indirect operand holds the address of a variable, usually an array or string. -It can be dereferenced (just like a pointer).

22 example

23 Arrays Array Sum Example
-Indirect operands are ideal for traversing an array -The register in brackets must be incremented by a value that matches the array type

24

25 Indexed Operands Indexed operands
-An indexed operand adds a constant to a register to generate an effective address. There are two notational forms: [label + reg] label[reg]

26 example

27 Pointers Pointers Declare a pointer variable that contains the offset of another variable

28 example

29 Shift instructions SHR/SAR/SHRD: Shifting Bits Right
SHR – shift logical right SAR – shift arithmetic right

30 Example of the SHR instruction

31 SHL/SAL/SHLR : Shifting Bits Left

32 Example:

33 JMP and Loop Instructions
JMP Instruction : JMP is an unconditional jump to a label that is usually within the same procedure . Syntax: JMP target Logic: EIP ← target JMP Example : top: . jmp top

34 LOOP Instruction LOOP Instruction
The LOOP instruction creates a counting loop Syntax: LOOP target The assembler calculates the distance, in bytes, between the offset of the following instruction and the offset of the target label. It is called the relative offset The relative offset is added to EIP.

35 LOOP Example Add 1 to AX each time the loop repeats
When the loop ends, AX = 5 and ECX = 0 mov ax, 0 mov ecx,5 L1: add ax loop L1

36 Unconditional Transfer Instructions

37 1. CALL and RET[n] Instructions
CALL instruction is to shift control to the procedure that is called. RET[n] instruction is to return control to the procedure that made the call. Usually the RET[n] instruction is the last instruction to be executed in the called procedure. Its format:

38

39 3. INT instruction enable program to interrupt its own processing
INT exits normal processing and access the Interrupt Vector Table in low memory to determine the address of requested routine. The operation then transfer to BIOS or OS for specified action and returns to the program to resume processing. Refer to section for examples of INT instructions.

40 Conditional JUMP Instructions
Format for conditional jump (Jnnn) is: There are varieties of conditional jump instructions that transfer control depending on settings in the flags register: ZF, CF, OF, AF and SF. Table below shows some example of conditional jump that are used for unsigned data. The LOOP A20 statement in Table 7.5.3, can be replaced by using the conditional statement, JNZ A20 and DEC CX as in Table

41 Table 7.7.2

42 conditional jump instructions usually used with other instructions: CMP, INC, DEC etc.
the following are examples of conditional jump instruction:

43

44 Thanks for listening


Download ppt "Data Transfers, Addressing, and Arithmetic"

Similar presentations


Ads by Google