Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lab 6 Stack.

Similar presentations


Presentation on theme: "Lab 6 Stack."— Presentation transcript:

1 Lab 6 Stack

2 Push & Pop Instructions
PUSH source POP destination 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

3 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, ;display first content MOV DX,CX INT 21H MOV AH, ;display second content MOV DX,BX MOV AH, ;display newline LEA DX,NL PUSH CX ;swapping contents PUSH BX POP CX POP BX MOV AH, ;display first contents MOV DX,CX INT 21H MOV AH, ;display second contents MOV DX,BX ret NL DB 0DH,0AH,"$"

4 Procedures Invoking procedures: CALL name name PROC ;body of procedure
ret name ENDP Invoking procedures: CALL name

5 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

6 Exercise Let the user input 2 numbers and display the result of multiplication.

7 Solution org 100h CALL INDEC MOV BX,AX CALL NEWL XOR AX,AX MUL BX
XOR BX,BX 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


Download ppt "Lab 6 Stack."

Similar presentations


Ads by Google