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

No comments:

Post a Comment

Popular Posts

Latest Post from my Other Blog