assembly language – lab 5 mul, div, stack, indec, outdec
TRANSCRIPT
![Page 1: Assembly Language – Lab 5 MUL, DIV, Stack, INDEC, OUTDEC](https://reader036.vdocuments.us/reader036/viewer/2022082315/56649dbe5503460f94ab24a1/html5/thumbnails/1.jpg)
Assembly Language – Lab 5MUL, DIV, Stack, INDEC, OUTDEC
![Page 2: Assembly Language – Lab 5 MUL, DIV, Stack, INDEC, OUTDEC](https://reader036.vdocuments.us/reader036/viewer/2022082315/56649dbe5503460f94ab24a1/html5/thumbnails/2.jpg)
MUL/IMUL Instructions• The MUL (Multiply) instruction handles unsigned data and the IMUL
(Integer Multiply) handles signed data.
• Example - 8-bit unsigned multiplication (5 * 10h):
MOV AL,5HMOV BL,10HMUL BL ; CF=0
![Page 3: Assembly Language – Lab 5 MUL, DIV, Stack, INDEC, OUTDEC](https://reader036.vdocuments.us/reader036/viewer/2022082315/56649dbe5503460f94ab24a1/html5/thumbnails/3.jpg)
Example 1• Program to multiply two 8 bit numbers.
![Page 4: Assembly Language – Lab 5 MUL, DIV, Stack, INDEC, OUTDEC](https://reader036.vdocuments.us/reader036/viewer/2022082315/56649dbe5503460f94ab24a1/html5/thumbnails/4.jpg)
DIV/IDIV Instructions• The division operation generates two elements - a quotient and a remainder.• The DIV instruction is used or unsigned data and the IDIV is used or signed
data.
![Page 5: Assembly Language – Lab 5 MUL, DIV, Stack, INDEC, OUTDEC](https://reader036.vdocuments.us/reader036/viewer/2022082315/56649dbe5503460f94ab24a1/html5/thumbnails/5.jpg)
DIV/IDIV Instructions (Example)• Divide 8003h by 100h, using 16-bit operands:
MOV DX,0 ; clear dividend, highMOV AX,8003H ; dividend, lowMOV CX,100H ; divisorDIV CX ; AX = 0080h, DX = 3
![Page 6: Assembly Language – Lab 5 MUL, DIV, Stack, INDEC, OUTDEC](https://reader036.vdocuments.us/reader036/viewer/2022082315/56649dbe5503460f94ab24a1/html5/thumbnails/6.jpg)
CBW, CWD Instructions• CBW (convert byte to word) extends AL into AH− If bit 7 of AL is a 1, the instruction will place FF in AH.− If bit 7 of AL is a 0, the instruction will place 00 in AH.
• CWD (convert word to doubleword) extends AX into DX− If bit 15 of AX is a 1, the instruction will place FFFF in DX.− If bit 15 of AX is a 0, the instruction will place 0000 in DX.
• NOTE: Use this instruction only with signed arithmetic.
![Page 7: Assembly Language – Lab 5 MUL, DIV, Stack, INDEC, OUTDEC](https://reader036.vdocuments.us/reader036/viewer/2022082315/56649dbe5503460f94ab24a1/html5/thumbnails/7.jpg)
Example 2• Divide 16 bit numbers by an 8 bit numbers.
![Page 8: Assembly Language – Lab 5 MUL, DIV, Stack, INDEC, OUTDEC](https://reader036.vdocuments.us/reader036/viewer/2022082315/56649dbe5503460f94ab24a1/html5/thumbnails/8.jpg)
PUSH/POP Instructions (Stack)• LIFO (Last-In, First-Out) data structure, items are added and removed from
one end of the structure.• To ‘push’ an item means to insert it, and to ‘pop’ an item means to remove it.• Managed by the CPU, using two registers:
• SS (stack segment)• ESP (stack pointer): point to the top of the stack.
stacksegment
SS
ESP
memory
![Page 9: Assembly Language – Lab 5 MUL, DIV, Stack, INDEC, OUTDEC](https://reader036.vdocuments.us/reader036/viewer/2022082315/56649dbe5503460f94ab24a1/html5/thumbnails/9.jpg)
Example 3• Program to swap the content of AX and BX.
![Page 10: Assembly Language – Lab 5 MUL, DIV, Stack, INDEC, OUTDEC](https://reader036.vdocuments.us/reader036/viewer/2022082315/56649dbe5503460f94ab24a1/html5/thumbnails/10.jpg)
Procedures• The procedure start with the name of the procedure followed by PROC
(reserved word), at the end of procedure write RET, also the procedure name followed with ENDP.
• To invoke a procedure, the CALL instruction is used.
name PROC..RET
name ENDP
![Page 11: Assembly Language – Lab 5 MUL, DIV, Stack, INDEC, OUTDEC](https://reader036.vdocuments.us/reader036/viewer/2022082315/56649dbe5503460f94ab24a1/html5/thumbnails/11.jpg)
INDEC / OUTDEC Procedures• Procedures used to read and print decimal data. • INDEC
Code of INDEC exist in file PGM9_3.ASM• OUTDEC
Code of OUTDEC exist in file PGM9_1.ASM
• Include the two files using INCLUDE directive. • Syntax: INCLUDE C:\emu8086\MySource/PGM9_3.ASM
INCLUDE C:\emu8086\MySource/PGM9_1.ASM
![Page 12: Assembly Language – Lab 5 MUL, DIV, Stack, INDEC, OUTDEC](https://reader036.vdocuments.us/reader036/viewer/2022082315/56649dbe5503460f94ab24a1/html5/thumbnails/12.jpg)
OUTDEC ProcedurePGM9_1.ASM
![Page 13: Assembly Language – Lab 5 MUL, DIV, Stack, INDEC, OUTDEC](https://reader036.vdocuments.us/reader036/viewer/2022082315/56649dbe5503460f94ab24a1/html5/thumbnails/13.jpg)
INDEC ProcedurePGM9_3.ASM
![Page 14: Assembly Language – Lab 5 MUL, DIV, Stack, INDEC, OUTDEC](https://reader036.vdocuments.us/reader036/viewer/2022082315/56649dbe5503460f94ab24a1/html5/thumbnails/14.jpg)
INDEC ProcedurePGM9_3.ASM
![Page 15: Assembly Language – Lab 5 MUL, DIV, Stack, INDEC, OUTDEC](https://reader036.vdocuments.us/reader036/viewer/2022082315/56649dbe5503460f94ab24a1/html5/thumbnails/15.jpg)
INDEC / OUTDEC ProceduresMAIN PROGRAM