ecx의 값이 0 인 후에 프로그램을 끝내고 싶을 때 왜 내 프로그램이 무한 루프에 빠지는 지 알 수는 없습니까? 도와주세요?조립! 루프를 종료 할 수 없습니까?
section .data
;get external functions
extern printf
global main
main:
;set up stack frame
push rbp
mov rbp, rsp
;if(x<y)
;print x is less
;else
;print y is larger than x
;mov values into register to compare them
mov rax,[x]
mov rbx,[y]
cmp rax,rbx ;cmp x,y
jg .x_is_greater
lea rdi,[y_less]
xor eax,eax ;must clear eax when using printf
call printf
jmp .done
.x_is_greater:
;print "X is greater to the screen"
;mov r11,[count]
;lea rdi,[x_greater]
;xor eax,eax
;call printf
;mov r12,[zero]
;cmp r11,r12
;jg .myloop ;jump to myloop if greater than zero
;jmp .done ;return if equal to 0
mov ecx, 3; [count]
;mov r12, [zero]
jmp .myloop
.myloop:
;;dec r11
;dec rcx
lea rdi,[fmt]
lea rsi,[ecx]
;mov rdx,[r12]
xor eax,eax ;must clear eax when using printf
call printf
cmp ecx, 0
jz .done
lea rdi,[x_greater]
xor eax,eax ;must clear eax when using printf
call printf
lea rdi,[fmt]
lea rsi,[ecx]
;mov rdx,[r12]
xor eax,eax ;must clear eax when using printf
call printf
dec ecx
;sub rcx,[one]
jmp .myloop
;jmp .done
.done:
leave
;xor eax, eax
ret;exit program
;leave ;destroy stack frame
section .bss
section .data
prompt db "This is a practice program to test what I know!",0x0a,0
y_less db "Y < X",0x0a,0
x_greater db "X > Y ",0x0a,0
x db 10
y db 1
count dq 3
zero db 0
one dq 1
fmt db "R11 %d ",0x0a,0
"이 작업을 수행 할 필요가 없습니다"... 64 비트 (사용중인 일부 레지스터를 기반으로하는 경우) 인 경우 ** 할 수 있습니다 ** 다양한 인수를 허용하는 함수를 호출 할 때'eax'를 지울 필요가 있습니다. 20 페이지의 각주 # 13을 참고하십시오. [http://www.x86-64.org/documentation/abi.pdf] (http://www.x86-64.org/documentation/abi.pdf). 또한 50.7 페이지에서 시작하는 3.5.7 절에 대한 추가 토론이 있습니다. – cbranch
+1은 알지 못했습니다. BTW는 그가'rax' 전체를 정리해야만하는 것 같습니다. –
기술적으로, 나는 단지 낮은 바이트 ('al') 만 실제로 사용된다고 생각하지만, 개인적으로는 가독성을 위해서'rax' 전체를 정리할 것입니다. – cbranch