Instruction set Arithmetic instruction Format Examples Comments ADD

  • Slides: 13
Download presentation
Instruction set

Instruction set

Arithmetic instruction Format Examples Comments ADD dest, src ADD AL, BL ADD DX, BX

Arithmetic instruction Format Examples Comments ADD dest, src ADD AL, BL ADD DX, BX ADD DX, num 1 ADD AX, 25 H AL = AL + BL DX = DX + BX DX = DX + NUM 1 AX = AX + 25 H Flags Affected: AF, CF, OF, PF, SF and ZF SUB dest, src SUB AX, 10 H SUB DX, CX AX=AX - 10 H DX=DX - CX Flags Affected: AF, CF, OF, PF, SF and ZF Instructi on

Instruction Format Examples Comments MUL source MOV AX, 100 H MOV CX, 02 H

Instruction Format Examples Comments MUL source MOV AX, 100 H MOV CX, 02 H MUL CX One of the operand in AL/AX result is 32 bit DX: AX; Flags : CF, OF rest of the flags are undefined DIV Source MOV AX, 0123 h MOV BL, 10 h Quotient in AL= 12; Remainder in AH=03 DIV BL DIVISION AH Remainder MULTIPLICATION AL Quotient Result (16 bits) AX Quotient AX Result (lower byte) AX Remainder DX Result (Higher byte) DX

Instruction Format Examples Comments CBW MOV AL, -26 CBW AL =-26 h = 11001010

Instruction Format Examples Comments CBW MOV AL, -26 CBW AL =-26 h = 11001010 AX= 11111001010 CWD MOV AX, -234 CWD AX = FDCCh DX: AX= FFFFFDCC

Logical instructions

Logical instructions

FORMAT NOT R/M Comments BL=00110101 BL= 11001010 AL=00110101 AL=AL. 0 Fh= 00000101 BL=00010110 CL=1111

FORMAT NOT R/M Comments BL=00110101 BL= 11001010 AL=00110101 AL=AL. 0 Fh= 00000101 BL=00010110 CL=1111 BL=BL+CL=1111 AL=0101 AL xor FAh=10100111 Flags Affected XOR R/M, Immediate/ R/M Example MOV BL, 35 h NOT BL MOV AL, 35 h AND AL, 0 Fh MOV BL, 22 h MOV CL, FFh OR BL, CL MOV AL, 55 h XOR AL, FAh TEST R/M, Immediate/ R/M MOV AL, 51 h TEST AL, 80 h AL=01010001 Test AL, 80 CF=OF=0, AF=? PF, SF, ZF updated AND R/M, Immediate/ R/M OR R/M, Immediate/ R/M CF=OF=0, AF=? PF, SF, ZF updated

Instructi Format Examples on CMP CMP BX, AX destination, source Comments BX= AX If

Instructi Format Examples on CMP CMP BX, AX destination, source Comments BX= AX If BX – AX = 0 BX < AX if BX- AX = -ve(SF is set) BX > AX otherwise. Flags Affected: CF, SF and ZF

Branch Instructions

Branch Instructions

Un conditional Near Far Jump Near Conditional Far Short +127 to -128 Intrasegment Near

Un conditional Near Far Jump Near Conditional Far Short +127 to -128 Intrasegment Near (+32767 to -32768) Intersegment Short +127 to -128 Near (+32767 to -32768) Intrasegment Intersegment

Intra segment : IP relative Direct Opcode disp. L Indirect Opcode MOD 100 R/M

Intra segment : IP relative Direct Opcode disp. L Indirect Opcode MOD 100 R/M IP = IP + D 8 IP= IP + D 16 disp. H Mem. L Mem. H IP <- REG 16 bit IP<- MEM 16 bit Inter segment : IP relative Direct Indirect Opcode disp. L Opcode MOD 101 R/M disp. H Seg. L Mem. L Seg. H Mem. H CS <- Seg IP<-displacement CS <- Seg IP<-REG / displacement