I've been working on a swap function in order or eventually implement bubble sort using x86 assembly.
(我一直在研究交换功能,以便最终使用x86程序集实现气泡排序。)
My code also includes a function which refactors given number ( from - to + and vise versa ) for another function later, which I've called before testing the swap function
(我的代码还包含一个函数,该函数可以在以后为另一个函数重构给定的数字(从-到+,反之亦然),在测试交换函数之前我已经调用过)
This is the code so far:
(到目前为止,这是代码:)
org 100h
jmp main
numToNeg dw -9
toSwap1 db 'a'
toSwap2 db 'b'
param1 equ 8
swap1 equ 12
swap2 equ 14
main:
push offset numToNeg
call refactor
mov ax, numToNeg
call print_num
PRINTN
PRINTN "Before Swap:"
mov al, toSwap1
Call print_al_chr ;This function prints the given char inside al
mov al, toSwap2
Call print_al_chr
push offset toSwap1
push offset toSwap2
call swap
PRINTN
PRINTN "After Swap:"
mov al, toSwap1
Call print_al_chr
mov al, toSwap2
Call print_al_chr
PROC refactor
push bp
push bx
push ax
mov bp, sp
mov bx, [bp + param1]
mov ax, [bx]
not ax
inc ax
mov [bx], ax
pop ax
pop bx
pop bp
retn 2
ENDP refactor
PROC swap
push bp
push ax
push cx
push bx
push di
mov di, [bp + swap1]
mov ax, [di]
mov bx, [bp + swap2]
mov cx, [bx]
mov [bx], ax
mov [di], cx
pop di
pop bx
pop cx
pop ax
pop bp
retn 4
ENDP swap
Now I'm 100% sure that the swap function is correct, so the problem is somewhere in my main function, but I couldn't figure that out by myself.
(现在,我100%确定交换功能正确,因此问题出在我的主函数中,但我自己无法解决。)
The stack looked alright to me when i debugged the code and I'm pretty stumped right now :/ (当我调试代码时,堆栈对我来说还不错,而我现在很沮丧:/)
To be clear, The function "print_al_chr" Is indeed working, and the implementation is inside another file I'm importing each time.
(需要明确的是,函数“ print_al_chr”确实可以正常工作,并且该实现在我每次导入的另一个文件中。)
At the start I thought that the problem might be with the 'equ' that I was using at the start, but I'm pretty sure that the values I have passed are indeed correct, because that in the function I'm pushing 5 registers, which takes 10 bytes of space overall, so the parameters should be in the 12 and 14 position. (一开始我以为问题可能出在我一开始使用的“ equ”,但是我很确定自己传递的值确实正确,因为在函数中我要压入5个寄存器,总共需要10个字节的空间,因此参数应位于12和14位置。)
Thanks :D
(感谢:D)
EDIT: I changed my function to this:
(编辑:我将函数更改为此:)
PROC swap
push bp
;push ah
;push cl
push bx
push di
mov di, [bp + swap1]
mov ah, [di]
mov bx, [bp + swap2]
mov cl, [bx]
mov [bx], ah
mov [di], cl
pop di
pop bx
;pop cl
;pop ah
pop bp
retn 4
ENDP swap
I couldn't push the registers ah and cl, so I just changed the equ values to 8 and 10. But it is still not working, I'm going to think about this meantime.
(我无法将寄存器ah和cl压入,所以我只是将equ值更改为8和10。但是它仍然无法正常工作,我将在此期间进行思考。)
ask by Kidsm translate from so