Search:

Submit Article

# Program that prompts the user to enter two binary numbers of up to 8 digits each, and print their sum on the next line in binary...

Posted By: Easy Tutor     Category: Assembly Language     Views: 6985

## Code for Program that prompts the user to enter two binary numbers of up to 8 digits each, and print their sum on the next line in binary... in Assembly Language

``` .MODEL SMALL
.STACK 100H

.DATA
PROMPT_1  DB  0DH,0AH,'Enter the first binary number ( max 8-digits ) : \$'
PROMPT_2  DB  0DH,0AH,'Enter the second binary number ( max 8-digits ) : \$'
PROMPT_3  DB  0DH,0AH,'The SUM of given binary numbers in binary form is : \$'
ILLEGAL   DB  0DH,0AH,'Illegal character. Try again.\$'

.CODE
MAIN PROC
MOV AX, @DATA                ; initialize DS
MOV DS, AX

@START_1:                    ; jump label
LEA DX, ILLEGAL            ; load and display the string ILLEGAL
MOV AH, 9
INT 21H

@START_2:                    ; jump label
XOR BX, BX                 ; clear BX

LEA DX, PROMPT_1           ; load and display the string PROMPT_1
MOV AH, 9
INT 21H

MOV CX, 8                  ; initialize loop counter
MOV AH, 1                  ; set input function

@LOOP_1:                   ; loop label
INT 21H                  ; read a character

CMP AL, 0DH              ; compare AL with CR

CMP CX, 8                ; compare CX with 8

@SKIP_1:                 ; jump label
AND AL, 0FH            ; convert ascii into decimal code
SHL BL, 1              ; shift BL towards left by 1 position
OR BL, AL              ; set the LSB of BL with LASB of AL

@EXIT_LOOP_1:              ; jump label

LEA DX, PROMPT_2           ; load and display the string PROMPT_2
MOV AH, 9
INT 21H

MOV CX, 8                  ; initialize loop counter
MOV AH, 1                  ; set input function

@LOOP_2:                   ; loop label
INT 21H                  ; read a character

CMP AL, 0DH              ; compare AL with CR

CMP CX, 8                ; compare CX with 8

@SKIP_2:                 ; jump label
AND AL, 0FH            ; convert ascii into decimal code
SHL BH, 1              ; shift BH towards left by 1 position
OR BH, AL              ; set the LSB of BH with LASB of AL

@EXIT_LOOP_2:              ; jump label

LEA DX, PROMPT_3           ; load and display the string PROMPT_3
MOV AH, 9
INT 21H

MOV AH, 2                ; print the digit 1 i.e. carry
MOV DL, 31H
INT 21H

@SKIP:                     ; jump label

MOV CX, 8                  ; initialize loop counter
MOV AH, 2                  ; set output function

@LOOP_3:                   ; loop label
SHL BL, 1                ; shift BL towards left by 1 position
MOV DL, 30H              ; set DL=0

@ONE:                    ; jump label
MOV DL, 31H            ; set DL=1

@DISPLAY:                ; jump label
INT 21H                ; print the character

MOV AH, 4CH                  ; return control to DOS
INT 21H
MAIN ENDP
END MAIN
```
Share:

 Easy Tutor author of Program that prompts the user to enter two binary numbers of up to 8 digits each, and print their sum on the next line in binary... is from United States. Easy Tutor says Hello Friends,I am Free Lance Tutor, who helped student in completing their homework. I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] comI have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada. I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.Thanks,Happy Programming :) View All Articles