我正在编写一个程序来打印出所有从0到100的数字,我需要找到一个变量的数字位数(在这种情况下变量为counter)。linux nasm程序集查找变量中保存的数字位数
这里是我的代码:
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
我需要找到长度,使我知道多少次来划分,也多少位数字打印变量计数器。
我怎样才能找到它是多久?
在此先感谢
2012-10-14
Progrmr
+0
如果只是0到100,为什么不上'X <10'和'X <100'测试?那么你不必计算整个事情... –