I am working through a set of tasks that I am using for practice, and one of the tasks requires you to read in an integer and add 1 to it.
Please enter a number: 4 5
The problem that I am having is that I can't figure out how to deal with place values. For example, if I were given the input 9, I can't figure out how to make that into 10 (set it to 1 and append a 0). And then, what if I were given the input 9999999? I would have to set specifically the first digit to 1, the rest zero, and append a zero!
Here is my code so far. All it does is read in the number of up to 32 bits, and print out that number (practice printing out multiple digits):
SECTION .data msg db "Please enter a number: ",0 msglen EQU $-msg sz EQU 32 NUL EQU 0 len EQU 32 SECTION .bss num resb len SECTION .text GLOBAL _start _start: Msg: ; display the message mov eax, 4 mov ebx, 1 mov ecx, msg mov edx, msglen int 80h Read: ; read in the number mov eax, 3 mov ebx, 1 mov ecx, num mov edx, len int 80h Length: ; Find length of string mov eax, num mov ebx, 0 loop: cmp BYTE[eax], NUL je Set inc eax inc ebx jmp loop Set: ; set up the registers and variables mov ecx, num Print: ; main section - prints out the number plus 1 cmp BYTE[ecx], NUL je Exit mov eax, 4 mov ebx, 1 mov edx, 1 ; NOTE- does not yet add 1 to the number int 80h inc ecx jmp Print Exit: ; exits safely mov eax, 1 mov ebx, 0 int 80h
So, how can I do this problem? Could someone post code, so that I can use that code in future programs?
Many thanks in advance,