Sunday, June 15, 2008

16 Bit number divided by an 8 bit number

The given program displays the set of instructions for division of a 8 bit number from a 16 bit number.

div Unsigned divide
Syntax: div op8
div op16
op8: 8-bit register or memory
op16: 16-bit register or memory
Action: If operand is op8, unsigned AL = AX / op8 and AH = AX % op8
If operand is op16, unsigned AX = DX::AX / op16 and DX = DX::AX % op16
Flags Affected: OF=?, SF=?, ZF=?, AF=?, PF=?, CF=?
Notes: Performs both division and modulus operations in one instruction.


-A
1376:0100 MOV AX, 1234
1376:0103 MOV BX, 36
1376:0106 DIV BX
1376:0108 MOV [2000], AX
1376:010B HLT
1376:010C
-T

AX=1234 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=1376 ES=1376 SS=1376 CS=1376 IP=0103 NV UP EI PL NZ NA PO NC
1376:0103 BB3600 MOV BX,0036
-T

AX=1234 BX=0036 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=1376 ES=1376 SS=1376 CS=1376 IP=0106 NV UP EI PL NZ NA PO NC
1376:0106 F7F3 DIV BX
-T

AX=0056 BX=0036 CX=0000 DX=0010 SP=FFEE BP=0000 SI=0000 DI=0000
DS=1376 ES=1376 SS=1376 CS=1376 IP=0108 NV UP EI PL NZ NA PO NC
1376:0108 A30020 MOV [2000],AX DS:2000=0000
-T

AX=0056 BX=0036 CX=0000 DX=0010 SP=FFEE BP=0000 SI=0000 DI=0000
DS=1376 ES=1376 SS=1376 CS=1376 IP=010B NV UP EI PL NZ NA PO NC
1376:010B F4 HLT

No comments: