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
変数カウンターを何回分割するか、また何桁を印刷するかを知るために、長さを見つける必要があります。
どのくらいの長さかを調べるにはどうすればよいですか?
前もって感謝します