xchg 2 “Pointers” - function assembly 8086












0














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










share|improve this question






















  • 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 '18 at 19:32






  • 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 '18 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 '18 at 19:43












  • @MichaelPetch Thank you very much, its work!
    – RonRahamim
    Nov 21 '18 at 20:02
















0














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










share|improve this question






















  • 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 '18 at 19:32






  • 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 '18 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 '18 at 19:43












  • @MichaelPetch Thank you very much, its work!
    – RonRahamim
    Nov 21 '18 at 20:02














0












0








0







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










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 19:27









RonRahamimRonRahamim

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 '18 at 19:32






  • 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 '18 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 '18 at 19:43












  • @MichaelPetch Thank you very much, its work!
    – RonRahamim
    Nov 21 '18 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 '18 at 19:32






  • 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 '18 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 '18 at 19:43












  • @MichaelPetch Thank you very much, its work!
    – RonRahamim
    Nov 21 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 at 19:43














@MichaelPetch Thank you very much, its work!
– RonRahamim
Nov 21 '18 at 20:02




@MichaelPetch Thank you very much, its work!
– RonRahamim
Nov 21 '18 at 20:02












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python