我正在裝配中實現。現在我有一個簡單的while循環,以eax = 1開始,然後循環到eax = 10。在循環中,我使用打印宏來打印進度(應該打印1 - 10),但它不起作用。如何在裝配環中打印整數
section .bss
buffer resd 1
section .text
global _start
%macro write 3
mov eax, 4
mov ebx, %1
mov ecx, %2
mov edx, %3
int 80H
%endmacro
_start:
xor eax, eax
inc eax
while:
cmp eax, 10
jg end
mov [buffer], eax
write 1, [buffer], 1
mov eax, [buffer]
inc eax
jmp while
end:
mov eax, 1
xor ebx, ebx
int 0x80
的C相當於是:
#include <stdio.h>
int main(void)
{
unsigned int i = 1;
while(i <= 10)
{
printf("%d", i);
i++;
}
return 0;
}
所以我的問題是..我如何使用寫宏來打印值?我需要改變什麼?
感謝
如果您使用匯編語言,則需要學習以十六進制讀取和思考。你當然可以代碼轉換爲十進制,將爲用戶註定輸出這樣做,但監視你的代碼時,它的二進制差的簡寫,而十六進制是接近理想之一。 – 2011-02-04 17:55:24