How can I print the following on one line?
The sum of <num> and <num2> is <sum>
Instead, it's printing on three lines:
Enter a number: 1
Enter a second number: 2
The sum of 1
and 2
equals 3
Here is my code:
section .data ;Data segment
userMsg db 'Enter a number: ' ;Ask the user to enter a number
lenUserMsg equ $-userMsg ;The length of the message
userMsg2 db 'Enter a second number: ' ;Ask the user to enter a number
lenUserMsg2 equ $-userMsg2 ;The length of the message
dispMsg db 'The sum of '
lenDispMsg equ $-dispMsg
dispMsg2 db ' and '
lenDispMsg2 equ $-dispMsg2
dispMsg3 db ' equals '
lenDispMsg3 equ $-dispMsg3
section .bss ;Uninitialized data
num resb 5
num2 resb 5
sum resb 5
section .text ;Code Segment
global _start
_start: ;User prompt
mov eax, 4
mov ebx, 1
mov ecx, userMsg
mov edx, lenUserMsg
int 80h
;Read and store the first user input
mov eax, 3
mov ebx, 2
mov ecx, num
mov edx, 5 ;5 bytes (numeric, 1 for sign) of that information
int 80h
;Second user input
mov eax, 4
mov ebx, 1
mov ecx, userMsg2
mov edx, lenUserMsg2
int 80h
;Read and store the second user input
mov eax, 3
mov ebx, 2
mov ecx, num2
mov edx, 5
int 80h
;'The sum of '
mov eax, 4
mov ebx, 1
mov ecx, dispMsg
mov edx, lenDispMsg
int 80h
;num
mov eax, 4
mov ebx, 1
mov ecx, num
mov edx, 5
int 80h
;' and '
mov eax, 4
mov ebx, 1
mov ecx, dispMsg2
mov edx, lenDispMsg2
int 80h
;num2
mov eax, 4
mov ebx, 1
mov ecx, num2
mov edx, 5
int 80h
;' equals '
mov eax, 4
mov ebx, 1
mov ecx, dispMsg3
mov edx, lenDispMsg3
int 80h
;Add the inputs
mov eax, [num]
sub eax, '0' ;convert from ASCII to decimal
mov ebx, [num2]
sub eax, '0'
add eax, ebx
add eax, '0'
mov [sum], eax
;Print the sum
mov eax, 4
mov ebx, 1
mov ecx, sum
mov edx, 5
int 0x80
; Exit code
mov eax, 1
mov ebx, 0
int 80h