我正在编写一个程序来打印从 0 到 100 的所有数字,并且我需要找到一个变量(在本例中为变量counter
)所持有的位数。
这是我的代码:
SECTION .data
len EQU 32
SECTION .bss
counter resd len
digit1 resd len
digit2 resd len
digit3 resd len
SECTION .text
GLOBAL _start
_start:
nop
Print:
mov eax, 4
mov ebx, 1
mov ecx, counter
mov edx, len
int 80h
Set:
mov BYTE [counter], 1
Divide:
; HERE IS WHERE I NEED TO FIND THE LENGTH OF THE VARIABLE COUNTER
; initial division
mov ax, [counter] ; number we want to print
mov ch, 10 ; we divide by ten to siphon digits
div ch ; divide our number by 10
; al now has 11, ah has 1
mov dh, ah ; save the remainder in dh
xor ah,ah
mov ch, 10 ; refill ch with the divisor
div ch ; al now has 1, ah now has 1
Move: ; now to move our digits to a printable state
mov [digit1], dh ; first digit is in edx
mov [digit2], ah
mov [digit3], al
Adjust:
add BYTE [digit1], '0'
add BYTE [digit2], '0'
add BYTE [digit3], '0'
Print:
mov eax, 4
mov ebx, 1
mov ecx, digit1
mov edx, len
int 80h
mov eax, 4
mov ebx, 1
mov ecx, digit2
mov edx, len
int 80h
mov eax, 4
mov ebx, 1
mov ecx, digit3
mov edx, len
int 80h
Exit:
mov eax, 1
mov ebx, 0
int 80h
我需要找到长度,以便知道要划分多少次以及打印变量计数器的位数。
我怎样才能找到它有多长?
提前致谢