I have written a similar version to your last post, with some small changes. Personally I would create callable functions for repeated code, but I wanted to keep it as similar to your code as possible, to help you understand the changes.
I kept your labels so you can study each block separately. I always fully comment my code, to make it easier to understand.
This code can be assembled into a DOS .com file. I didn't test it, but believe it is OK. To convert to Linux code, you will need to look up Linux system calls and/or get more help elsewhere.
section .data
msg1 db 'Please enter the first 8-bit binary number: ', 0DH, 0AH
msg2 db 'Please enter the second 8-bit binary number: ', 0DH, 0AH
msg3 db 0DH, 0AH, 'The sum of the given binary numbers is:', 0DH, 0AH
invalid db 'Invalid input, try again.', 0DH,0AH
section .text
org 100h ; only needed if assembling as a DOS .com file
_start:
push cs
pop ds ; set data segment
xor bx, bx ; used to store input
lea dx, msg1 ;
mov ah, 9 ;
int 21h ; output first message using DOS interrupt
mov cx,8 ; loop counter
mov ah,1 ; DOS int 21h function for keyboard input
_loop_1:
int 21h ; get character input
sub al,"0" ; convert character input to binary digit
cmp al,1 ; is input a valid binary digit?
ja error ; if not, jump to error
shl bl,bl ;
add bl,al ; store this character
loop _loop_1 ; fetch next digit
int 21h ; fetch final character
cmp al,0Dh ; is this a carriage return?
ja error ; if not, jump to error
lea dx, msg2 ;
mov ah, 9 ;
int 21h ; output second message using DOS interrupt
mov cx,8 ; loop counter
mov ah,1 ; DOS int 21h function for keyboard input
_loop_2:
int 21h ; get character input
sub al,"0" ; convert character input to binary digit
cmp al,1 ; is input a valid binary digit?
ja error ; if not, jump to error
shl bh,bh ;
add bh,al ; store this character
loop _loop_2 ; fetch next digit
int 21h ; fetch final character
cmp al,0Dh ; is this a carriage return?
ja error ; if not, jump to error
lea dx, msg3 ;
mov ah, 9 ;
int 21h ; output third message using DOS interrupt
mov ah,2 ; DOS function 2 outputs a single character
adc bl,bh ; add both numbers, using carry flag for overflow
jnc _next ; if result is only 8-bits, skip this short section
mov dl,"1"
int 21h ; output "1"
_next:
mov cx,8
xor bh,bh
_loop_3:
shl bx,1
and bh,1 ; is next digit 0 or 1?
jnz _one
mov dl,"0" ; next digit is 0
jmp _display:
_one:
mov dl,"1" ; next digit is 1
_display
int 21h ; output this character
loop _loop_3
_exit:
mov ax,04C00h
int 21h ; exit with error code 0
_error:
lea dx, invalid ;
mov ah, 9 ;
int 21h ; output error message using DOS interrupt
jmp _start: