DATA TRANSFER ADDRESSING AND ARITHMETIC 1 Data Transfer

  • Slides: 9
Download presentation
DATA TRANSFER, ADDRESSING AND ARITHMETIC 1

DATA TRANSFER, ADDRESSING AND ARITHMETIC 1

Data Transfer Instructions (Operand Types) • Instruction Format • [label: ] mnemonic [operands][ ;

Data Transfer Instructions (Operand Types) • Instruction Format • [label: ] mnemonic [operands][ ; comment ] • Can have one, two or three operands. • Syntax: • • mnemonic [destination], [source-1], [source-2] 2

Three Types of Operands • Three basic types of operands: • Immediate – a

Three Types of Operands • Three basic types of operands: • Immediate – a constant integer (8, 16, or 32 bits) • An immediate operand is a constant value or the result of a constant expression. • 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

Operands Types 4

Operands Types 4

MOV Instruction • It copies data from source operand to a destination operand. •

MOV Instruction • It copies data from source operand to a destination operand. • Also called as data transfer instruction. • Syntax: MOV destination, source • Destination operand’s contents changes, but source always remain unchanges. • MOV is for moving data between: • Memory • Register • Immediate (constant) 5

MOV Instruction • Rules for MOV instruction • Both operands must be the same

MOV Instruction • Rules for MOV instruction • Both operands must be the same size • No more than one memory operand permitted (memory to memory transfer is not allowed). • CS (Code Segment), EIP (Extended Instruction Pointer), and IP (Instruction Pointer) cannot be the destination • No immediate to segment moves: An immediate value cannot be moved to a segment register. • Segment Registers (Code, Data, Extra and Stack registers) are address registers. 6

MOV Instruction • Variants of MOV • • • MOV reg, reg MOV mem,

MOV Instruction • Variants of MOV • • • MOV reg, reg MOV mem, reg MOV reg, mem MOV mem, imm MOV reg, imm • Memory to Memory • A single MOV instruction cannot be used to move data directly from one memory location to another. • Instead source operand’s value must move to a register before moving its value to a memory operand. . data var 1 WORD ? var 2 WORD ? . code mov ax, var 1 mov var 2, ax 7

LAHF Instructions • LAHF (Load Status Flags into AH): • This instruction save a

LAHF Instructions • LAHF (Load Status Flags into AH): • This instruction save a copy of flag in a variable for safekeeping. • The LAHF instruction copies the low byte of the EFLAGS (Flag =16 bit, Eflag=32 bit) register into AH. • E. g of Flags. Sign, Zero, Auxiliary Carry, Parity, and Carry. • Example. data saveflags BYTE ? . code lahf ; load flags into AH mov saveflags, ah ; save them in a variable 8

SAHF Instructions • SAHF(Store AH into Status Flag) • Instruction copies AH into the

SAHF Instructions • SAHF(Store AH into Status Flag) • Instruction copies AH into the low byte of the EFLAGS register. • Example. data saveflags BYTE ? . code mov ah, saveflags ; load saved flags into AH sahf ; copy into Flags register 9