Showing posts with label stack. Show all posts
Showing posts with label stack. Show all posts

Thursday, May 13, 2010

Stack programming tutorial

Question
Based on the following instruction, state the final value of AX,BX dan CX. Then draw the stack produce at 'PUSH CX' instruction. [Assume SS:5000h ; SP:0305h ]

 MODEL SMALL
.STACK
.STARTUP

MOV AX, 1000H
MOV BX, 2000H
MOV CX, 3000H

PUSH AX
PUSH BX
PUSH CX

POP AX
POP CX
POP BX

.EXIT
END

Answer

Final value:
AX=3000h
BX=2000h
CX=1000h

Address Data
50301    3000h
50303    2000h
50305    1000h

Wednesday, May 12, 2010

Exchange register content using stack segment tutorial

 Question
Write a sequence of instructions to exchange two register's content using stack in assembly language?

Answer
Let say the register is AX and BX. To exchange the register's content for both by using stack it can be done by using POP and PUSH instruction. Stack behave as last in first out (LIFO).


PUSH AX // ax data will be copied into the stack, Stack pointer (SP) decreased by 2
PUSH BX // bx data will be copied into the stack 'above' ax data, Stack pointer (SP) decreased by another 2
POP AX // the data that originally came from 'bx' will be popped into AX and removed from the stack. Stack pointer added by 2
POP BX // the data that originally came from 'ax' (remember,bx data already removed from the stack) will be popped into AX and removed from the stack. Stack pointer added by 2

Popular Posts

Latest Post from my Other Blog