70 likes | 151 Views
Lab 6. Stack. Push & Pop Instructions. POP destination. PUSH source. Last in First Out, First in Last Out SP initialized to 100H which represent empty stack. SP might contain offset address. (Stack Not Empty) PUSH decreases SP by 2 POP increases SP by 2. Example 1.
E N D
Lab 6 Stack
Push & Pop Instructions • POP destination • PUSH source Last in First Out, First in Last Out SP initialized to 100H which represent empty stack. SP might contain offset address. (Stack Not Empty) PUSH decreases SP by 2 POP increases SP by 2
Example 1 • Swap contents of CX = 30H and BX=32H, display it before and after swapping org 100h MOV CX,30H ;moving contents into registers MOV BX,32H MOV AH,2 ;display first content MOV DX,CX INT 21H MOV AH,2 ;display second content MOV DX,BX INT 21H MOV AH,9 ;display newline LEA DX,NL INT 21H PUSH CX ;swapping contents PUSH BX POP CX POP BX MOV AH,2 ;display first contents MOV DX,CX INT 21H MOV AH,2 ;display second contents MOV DX,BX INT 21H ret NL DB 0DH,0AH,"$"
Procedures Invoking procedures: • CALL name • name PROC ;body of procedure ret name ENDP
INDEC / OUTDEC • Input and display it in a new line. org 100h CALL INDEC MOV BX,AX MOV AH,9 LEA DX,NL INT 21H MOV AX,BX CALL OUTDEC ret NL DB 0DH,0AH,"$" INCLUDE 'PGM9_1.ASM' INCLUDE 'PGM9_3.ASM' END
Exercise • Let the user input 2 numbers and displaythe result of multiplication.
Solution org 100h CALL INDEC MOV BX,AX CALL NEWL XOR AX,AX CALL INDEC MUL BX XOR BX,BX MOV BX,AX CALL NEWL MOV AX,BX CALL OUTDEC ret NL DB 0DH,0AH,"$" NEWL PROC MOV AH,9 LEA DX,NL INT 21H RET NEWL ENDP INCLUDE 'PGM9_1.ASM' INCLUDE 'PGM9_3.ASM' END