Hello,
I'm having trouble understanding how to add with carry.
I made a program where the input(numbers) ends up in the AL register as a binary number (ASCII) code for the number pressed. What I have to do is convert it to the right numerical value. Well I did that.
The user has to input 4 digits and my program is supposed to add them. However, since 4 digits mean the number is above 255, I'm getting the wrong result. The overflow problem. I'm supposed to use the Multiplication with carry or the Addition with carry. But, it isn't working.
My output using the digits 0255
Please enter an integer that contains 4 digits or less:
0255
255
My output using the digits 0256
Please enter an integer that contains 4 digits or less:
0256
0
%include "/tools/lib/asm_io.inc"
segment .data
welcome_msg db 'Program Name: Lab 4', 0
prompt_msg db 'Please enter an integer that contains 4 digits or less: ', 0
typed_msg db 'You typed the number: ', 0
end_msg db 'Program has ended', 0
global _main
segment .text
_main:
enter 0, 0
mov eax, 0
mov eax, welcome_msg
call print_string ;Prints Program's Name
call print_nl
mov eax, prompt_msg
call print_string
call print_nl
mov ecx, 4 ;Sets counter to 3
mov dl, 0 ;dl = old number
mov bl, 0
call get_number
call print_nl
mov al, dl
call print_int
leave
ret
get_number:
call multiplication
call get_kb
sub al, 30h
call print_int
adc dl, al
mov bl, dl
dec ecx
jnz get_number
ret
multiplication:
adc dl, bl
adc dl, bl
adc dl, bl
adc dl, bl
adc dl, bl
adc dl, bl
adc dl, bl
adc dl, bl
adc dl, bl
ret
Thank you for your time.