xchg 2 “Pointers” - function assembly 8086
up vote
0
down vote
favorite
I got a mission to build a function thats replace 2 pointers values.
There is my code:
org 100h
jmp main
toSwap1 db 'a'
toSwap2 db 'b'
result dw ?
numToNeg dw -9
string db 'm', 'a', 'g', 's', 'h', 'i', 'm', 'i', 'm', 'v', 'e', 'n', 'e', 'h', 'e', 'n', 'i', 'm' ,0Dh,0Ah,'$'
array db "0000", 0Dh,0Ah, 24h ; line feed return and stop symbol 24h=$ (ASCII).
num1 dw 0xAC45
; There is some vars thats i need for other missions
main:
; Second function: should print b and a - MAIN CODE FOR FUNC ~
push offset toSwap1
push offset toSwap2
call xChange
mov al, toSwap1
call print_al_chr
PRINTN "and"
mov al, toSwap2
call print_al_chr
mov ah, 0
int 16h
ret
xChange proc ; THE FUNC ~
push bp
push ax
push bx
push cx
mov bp, sp
mov bx, [bp + 12]
mov al, [bx]
mov bx, [bp + 10]
mov cx, [bx]
mov [bx], ax
mov bx, [bp + 12]
mov [bx], cx
pop cx
pop bx
pop ax
pop bp
retn 4
xChange endp
Now the problem is that the value of the second var (thats should print 'a' at the end of the function got reset)....
picture:
enter image description here
function pointers stack x86-16 emu8086
add a comment |
up vote
0
down vote
favorite
I got a mission to build a function thats replace 2 pointers values.
There is my code:
org 100h
jmp main
toSwap1 db 'a'
toSwap2 db 'b'
result dw ?
numToNeg dw -9
string db 'm', 'a', 'g', 's', 'h', 'i', 'm', 'i', 'm', 'v', 'e', 'n', 'e', 'h', 'e', 'n', 'i', 'm' ,0Dh,0Ah,'$'
array db "0000", 0Dh,0Ah, 24h ; line feed return and stop symbol 24h=$ (ASCII).
num1 dw 0xAC45
; There is some vars thats i need for other missions
main:
; Second function: should print b and a - MAIN CODE FOR FUNC ~
push offset toSwap1
push offset toSwap2
call xChange
mov al, toSwap1
call print_al_chr
PRINTN "and"
mov al, toSwap2
call print_al_chr
mov ah, 0
int 16h
ret
xChange proc ; THE FUNC ~
push bp
push ax
push bx
push cx
mov bp, sp
mov bx, [bp + 12]
mov al, [bx]
mov bx, [bp + 10]
mov cx, [bx]
mov [bx], ax
mov bx, [bp + 12]
mov [bx], cx
pop cx
pop bx
pop ax
pop bp
retn 4
xChange endp
Now the problem is that the value of the second var (thats should print 'a' at the end of the function got reset)....
picture:
enter image description here
function pointers stack x86-16 emu8086
Explain in words what the problem is, not just with a picture of your IDE with a bunch of windows. Minimal, Complete, and Verifiable example.
– Peter Cordes
Nov 21 at 19:32
1
You're loadingal
(which matched yourdb
data size), but then you're loadingcx
and storingax
(16 bits).
– Peter Cordes
Nov 21 at 19:33
Because yourxChange
proc writes 16-bits of data (word) into the destination, rather than a byte.mov [bx], ax
should bemov [bx], al
andmov [bx], cx
should bemov [bx], cl
. As well it is often more convenient to putmov bp,sp
right afterpush bp
. This way the first parameter will always be at bp+4 (assuming the return address is near)
– Michael Petch
Nov 21 at 19:43
@MichaelPetch Thank you very much, its work!
– RonRahamim
Nov 21 at 20:02
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I got a mission to build a function thats replace 2 pointers values.
There is my code:
org 100h
jmp main
toSwap1 db 'a'
toSwap2 db 'b'
result dw ?
numToNeg dw -9
string db 'm', 'a', 'g', 's', 'h', 'i', 'm', 'i', 'm', 'v', 'e', 'n', 'e', 'h', 'e', 'n', 'i', 'm' ,0Dh,0Ah,'$'
array db "0000", 0Dh,0Ah, 24h ; line feed return and stop symbol 24h=$ (ASCII).
num1 dw 0xAC45
; There is some vars thats i need for other missions
main:
; Second function: should print b and a - MAIN CODE FOR FUNC ~
push offset toSwap1
push offset toSwap2
call xChange
mov al, toSwap1
call print_al_chr
PRINTN "and"
mov al, toSwap2
call print_al_chr
mov ah, 0
int 16h
ret
xChange proc ; THE FUNC ~
push bp
push ax
push bx
push cx
mov bp, sp
mov bx, [bp + 12]
mov al, [bx]
mov bx, [bp + 10]
mov cx, [bx]
mov [bx], ax
mov bx, [bp + 12]
mov [bx], cx
pop cx
pop bx
pop ax
pop bp
retn 4
xChange endp
Now the problem is that the value of the second var (thats should print 'a' at the end of the function got reset)....
picture:
enter image description here
function pointers stack x86-16 emu8086
I got a mission to build a function thats replace 2 pointers values.
There is my code:
org 100h
jmp main
toSwap1 db 'a'
toSwap2 db 'b'
result dw ?
numToNeg dw -9
string db 'm', 'a', 'g', 's', 'h', 'i', 'm', 'i', 'm', 'v', 'e', 'n', 'e', 'h', 'e', 'n', 'i', 'm' ,0Dh,0Ah,'$'
array db "0000", 0Dh,0Ah, 24h ; line feed return and stop symbol 24h=$ (ASCII).
num1 dw 0xAC45
; There is some vars thats i need for other missions
main:
; Second function: should print b and a - MAIN CODE FOR FUNC ~
push offset toSwap1
push offset toSwap2
call xChange
mov al, toSwap1
call print_al_chr
PRINTN "and"
mov al, toSwap2
call print_al_chr
mov ah, 0
int 16h
ret
xChange proc ; THE FUNC ~
push bp
push ax
push bx
push cx
mov bp, sp
mov bx, [bp + 12]
mov al, [bx]
mov bx, [bp + 10]
mov cx, [bx]
mov [bx], ax
mov bx, [bp + 12]
mov [bx], cx
pop cx
pop bx
pop ax
pop bp
retn 4
xChange endp
Now the problem is that the value of the second var (thats should print 'a' at the end of the function got reset)....
picture:
enter image description here
function pointers stack x86-16 emu8086
function pointers stack x86-16 emu8086
asked Nov 21 at 19:27
RonRahamim
12
12
Explain in words what the problem is, not just with a picture of your IDE with a bunch of windows. Minimal, Complete, and Verifiable example.
– Peter Cordes
Nov 21 at 19:32
1
You're loadingal
(which matched yourdb
data size), but then you're loadingcx
and storingax
(16 bits).
– Peter Cordes
Nov 21 at 19:33
Because yourxChange
proc writes 16-bits of data (word) into the destination, rather than a byte.mov [bx], ax
should bemov [bx], al
andmov [bx], cx
should bemov [bx], cl
. As well it is often more convenient to putmov bp,sp
right afterpush bp
. This way the first parameter will always be at bp+4 (assuming the return address is near)
– Michael Petch
Nov 21 at 19:43
@MichaelPetch Thank you very much, its work!
– RonRahamim
Nov 21 at 20:02
add a comment |
Explain in words what the problem is, not just with a picture of your IDE with a bunch of windows. Minimal, Complete, and Verifiable example.
– Peter Cordes
Nov 21 at 19:32
1
You're loadingal
(which matched yourdb
data size), but then you're loadingcx
and storingax
(16 bits).
– Peter Cordes
Nov 21 at 19:33
Because yourxChange
proc writes 16-bits of data (word) into the destination, rather than a byte.mov [bx], ax
should bemov [bx], al
andmov [bx], cx
should bemov [bx], cl
. As well it is often more convenient to putmov bp,sp
right afterpush bp
. This way the first parameter will always be at bp+4 (assuming the return address is near)
– Michael Petch
Nov 21 at 19:43
@MichaelPetch Thank you very much, its work!
– RonRahamim
Nov 21 at 20:02
Explain in words what the problem is, not just with a picture of your IDE with a bunch of windows. Minimal, Complete, and Verifiable example.
– Peter Cordes
Nov 21 at 19:32
Explain in words what the problem is, not just with a picture of your IDE with a bunch of windows. Minimal, Complete, and Verifiable example.
– Peter Cordes
Nov 21 at 19:32
1
1
You're loading
al
(which matched your db
data size), but then you're loading cx
and storing ax
(16 bits).– Peter Cordes
Nov 21 at 19:33
You're loading
al
(which matched your db
data size), but then you're loading cx
and storing ax
(16 bits).– Peter Cordes
Nov 21 at 19:33
Because your
xChange
proc writes 16-bits of data (word) into the destination, rather than a byte. mov [bx], ax
should be mov [bx], al
and mov [bx], cx
should be mov [bx], cl
. As well it is often more convenient to put mov bp,sp
right after push bp
. This way the first parameter will always be at bp+4 (assuming the return address is near)– Michael Petch
Nov 21 at 19:43
Because your
xChange
proc writes 16-bits of data (word) into the destination, rather than a byte. mov [bx], ax
should be mov [bx], al
and mov [bx], cx
should be mov [bx], cl
. As well it is often more convenient to put mov bp,sp
right after push bp
. This way the first parameter will always be at bp+4 (assuming the return address is near)– Michael Petch
Nov 21 at 19:43
@MichaelPetch Thank you very much, its work!
– RonRahamim
Nov 21 at 20:02
@MichaelPetch Thank you very much, its work!
– RonRahamim
Nov 21 at 20:02
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419261%2fxchg-2-pointers-function-assembly-8086%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Explain in words what the problem is, not just with a picture of your IDE with a bunch of windows. Minimal, Complete, and Verifiable example.
– Peter Cordes
Nov 21 at 19:32
1
You're loading
al
(which matched yourdb
data size), but then you're loadingcx
and storingax
(16 bits).– Peter Cordes
Nov 21 at 19:33
Because your
xChange
proc writes 16-bits of data (word) into the destination, rather than a byte.mov [bx], ax
should bemov [bx], al
andmov [bx], cx
should bemov [bx], cl
. As well it is often more convenient to putmov bp,sp
right afterpush bp
. This way the first parameter will always be at bp+4 (assuming the return address is near)– Michael Petch
Nov 21 at 19:43
@MichaelPetch Thank you very much, its work!
– RonRahamim
Nov 21 at 20:02