我正在尝试实现一个程序,该程序比较来自两个不同列表的一对数字并存储最大数字。这必须使用EBP寄存器来访问参数。
segment .bss
ans resb 4
buff resb 4
largest resb 4
test2 resb 1
segment .data
num1 db 1,2,3,4
num2 db 5,1,7,2
msg1: db " "
msg_size1: equ $-msg1
space1: db " "
space1_size: equ $-space1
segment .text
global _start
_start:
mov byte[test2], 0
mov word[largest], 0
mov word[ans], 0
mov word[buff], 0
mov esi, 0
mov bx, 0
label1:
cmp esi, 3
jg label3
mov ecx, [num1+esi]
mov edx, [num2+esi]
push ecx
push edx
;;mov dword[test2], esi
call which_is_larger_procedure
add esp, 8
mov eax, [num2+esi]
mov [ans], eax
;;mov esi, dword[test2]
;; mov [buff], esi
;;; ; outut
;; mov eax, 4 ; system_write
;; mov ebx, 1 ; stdout
;; mov ecx, [ans] ; move biggest element to accumulator
;; add ecx, 30h ; convert to ascii representation
;; mov [buff], ecx ; move to memory
;; mov ecx, buff ; put pointer in ecx for printing
;; mov edx, 4 ; size, 4 bytes
;; int 80h ; sytem call.
inc esi
jmp label1
label3:
exit:
mov eax, 1
mov ebx, 0
int 80h
which_is_larger_procedure:
;;; ; Body
push ebp
mov ebp, esp
sub esp, 8
push eax
push ebx
mov ecx, [ebp+8]
mov edx, [ebp+12]
mov eax, [ecx]
mov ebx, [edx]
cmp al, bl
jg CL_g_DL
cmp byte[largest], bl
jg skip
mov byte[largest], bl
AL_g_BL: ;If AH is Larger than BL
cmp byte[largest], al
jg skip
mov byte[largest], al
label5:
skip:
;;; ; ; outut
mov eax, 4 ; system_write
mov ebx, 1 ; stdout
mov ecx, [largest] ; move biggest element to accumulator
add ecx, 30h ; convert to ascii representation
mov [buff], ecx ; move to memory
mov ecx, buff ; put pointer in ecx for printing
mov edx, 4 ; size, 4 bytes
int 80h ; sytem call.
;;; ; Outout
mov eax, 4 ; system_write
mov ebx, 1 ; stdout
mov ecx, msg1 ; put pointer in ecx for printing
int 80h ; sytem call.
pop ecx
pop edx
add esp, 8
pop ebp
ret
有些代码稍微遗留下来试验为什么会出现这种代码,
遵循本教程:tutorial
答案 0 :(得分:0)
当我试图弄清楚如何使用GDB来调试它时,一位正在查看我的代码的朋友发现了问题。
mov eax, [ecx]
mov ebx, [edx]
这里的问题是我通过简单地删除问题得到解决的括号来取消引用保存实际数据而非内存地址的寄存器。
mov eax, ecx
mov ebx, edx
应该如何。