Часть моей программы NASM пытается взять целое число и преобразовать его в ASCII для печати на экране, и он не работает.Я не могу сказать, почему нет.Проигнорируйте материал о делении пополам / удвоении - это для другой части программы, которую я пропустил.
Вот мой код:
segment .data ;data segment
return db 0xA ;return character
segment .bss ;uninitialized data
numc resb 4 ;reserve 4 bytes for the converted number (int)
numh resb 5 ;reserve 5 bytes for halved input number
numha resb 5 ;reserve 5 bytes for the halved number in ascii form
numd resb 5 ;reserve 5 bytes for doubled input number
numda resb 5 ;reserve 5 bytes for the doubled number in ascii form
segment .text ;code segment
global _start ;global program name
_start:
mov ebx, 1234 ;number to be converted
mov [numc], ebx
_inttoascii: ;set registers up
mov eax, [numc]
xor ebx, ebx
xor edx, edx
mov ecx, 32
_loop2:
xor edx, edx ;clear edx
mov ebx, 10 ;divide eax by ten
div ebx
add edx, 48 ;add 48 to the remainder (ascii of 0 is 48)
mov [numha+ecx], edx ;move result to the correct spot in memory
sub ecx, 8 ;switch to another byte for next iteration
cmp eax, 0 ;if eax register is exhausted, we're done.
jg _loop2
_inttoascii2: ;set registers up
mov eax, [numc]
xor ebx, ebx
xor edx, edx
mov ecx, 32
_loop3:
xor edx, edx ;clear edx
mov ebx, 10 ;divide eax by ten
div ebx
add edx, 48 ;add 48 to the remainder (ascii of 0 is 48)
mov [numda+ecx], edx ;move result to the correct spot in memory
sub ecx, 8 ;switch to another byte for next iteration
cmp eax, 0 ;if eax register is exhausted, we're done.
jg _loop3
mov eax, 4 ;select kernel call #4 (write number storing half)
mov ebx, 1 ;default output device
mov ecx, numha ;pointer to numh
mov edx, 5 ;length of numh
int 0x80 ;kernel call to write
mov eax, 4 ;select kernel call #4 (new line)
mov ebx, 1 ;default output device
mov ecx, return ;pointer to return character
mov edx, 1 ;length of return character
int 0x80
mov eax, 4 ;select kernel call #4 (write number storing double)
mov ebx, 1 ;default output device
mov ecx, numda ;pointer to numd
mov edx, 5 ;length of numd
int 0x80 ;kernel call to write
mov eax,4 ;select kernel call #4 (new line)
mov ebx,1 ;default output device
mov ecx, return ;pointer to return character
mov edx, 1 ;length of return character
int 0x80 ;kernel call to write
exit: mov eax, 1 ;select system call #1
int 0x80 ;kernel call to exit
Выходной атм - просто пустые строки.