DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Assembly (http://www.daniweb.com/forums/forum125.html)
-   -   Push Instruction (http://www.daniweb.com/forums/thread42263.html)

-EMAN- Mar 30th, 2006 9:09 am
Push Instruction
 
What is the set of Instructions that equivallent to

Push [si]?

Narue Mar 30th, 2006 11:56 am
Re: Push Instruction
 
The behavior is equivalent to:
sub        sp,2
mov        [sp],[si]
But that's not valid code because sp can't be used for addressing and memory to memory moves are illegal. To get the same effect legally, you could do this:
sub        sp,2
mov        bp,sp
mov        ax,[si]
mov        [bp],ax
But that makes use of two extra registers. Better to simply use push, no? :)

-EMAN- Mar 30th, 2006 12:09 pm
Re: Push Instruction
 
YA PUSH IS EASY , BUT THIS IS A QUESTION IN MY TEST

I WAS SOLVE IT IN ANOTHER WAY :


push [SI]

MOV BX,[SI]
MOV DI,SP
DEC DI
MOV [DI],BH
DEC DI
MOV [DI],BL
MOV SP,DI

is it true ?? :o

-EMAN- Apr 1st, 2006 8:38 am
Re: Push Instruction
 
:?: is it false when i use DI instead of Bp


sub        sp,2
mov        di,sp
mov        ax,[si]
mov        [di],ax

:?: :?: i wait 4 ur reply

Narue Apr 1st, 2006 9:35 am
Re: Push Instruction
 
>is it false when i use DI instead of Bp
No, di can be used for addressing just as easily as bp. However, it benefits clarity to use the registers that are traditionally expected, and bp is expected as a reference to the stack pointer even if it isn't required. Thats like using bx as a loop counter instead of cx. Readers will pause to wonder why you chose to do something different.

>is it true ??
No. If you're using bx then I'll wager you're working in 16-bit mode rather than 8-bit mode. In that case, the stack is set at 16 bits, no matter what you try to push onto it. So when you decrement di, you're moving it by 16 bits instead of 8, which will give you *two* pushes. Even worse, the first value you push has an indeterminate low byte and the second value has an indeterminate high byte. This would be better:
push [SI]

MOV BX,[SI]
MOV DI,SP
DEC DI
MOV [DI],BX
MOV SP,DI

-EMAN- Apr 1st, 2006 12:56 pm
:o thnkx


All times are GMT -4. The time now is 5:51 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC