Question

In: Computer Science

NASM - Create a program that adds two binary numbers and returns the result in binary.

NASM - Create a program that adds two binary numbers and returns the result in binary.

Solutions

Expert Solution

SOLUTION:

this is a 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. If the user enters an illegal character, he or she should be prompted to begin again. Each input ends with a carriage return.

.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_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
JNE @SKIP_1 ; jump to label @SKIP_1 if AL!=0DH
JMP @EXIT_LOOP_1 ; jump to label @EXIT_LOOP_1

@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
LOOP @LOOP_1 ; jump to label @LOOP_1 if CX!=0

@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
JNE @SKIP_2 ; jump to label @SKIP_2 if AL!=0DH
JMP @EXIT_LOOP_2 ; jump to label @EXIT_LOOP_2

@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
LOOP @LOOP_2 ; jump to label @LOOP_2 if CX!=0

@EXIT_LOOP_2: ; jump label

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

ADD BL, BH ; add BL and BH
JNC @SKIP ; jump to label @SKIP if CF=1
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
JC @ONE ; jump to label @ONE if CF=1
MOV DL, 30H ; set DL=0
JMP @DISPLAY ; jump to label @DISPLAY

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

@DISPLAY: ; jump label
INT 21H ; print the character
LOOP @LOOP_3 ; jump to label @LOOP_3 if CX!=0

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

**Hope you liked it.....Please upvote me**


Related Solutions

In Python please:  Number the Lines in a File: Create a program that adds line numbers to...
In Python please:  Number the Lines in a File: Create a program that adds line numbers to a file. The name of the input file will be read from the user, as will the name of the new file that your program will create. Each line in the output file should begin with the line number, followed by a colon and a space, followed by the line from the input file.
Write a JavaFx program for addition of two numbers. (create text as Number1, Number2 and Result...
Write a JavaFx program for addition of two numbers. (create text as Number1, Number2 and Result and create 3 textfileds. Create sum button. You have to enter number1 and number2 in the textfileds. If you click the button Sum, the result will be showed in the third text field.
The result of subtracting the following two signed binary numbers on an eight bit machine is...
The result of subtracting the following two signed binary numbers on an eight bit machine is      10110011    - 01101001
Develop a python program to convert two decimal numbers (A and B) to binary numbers. You...
Develop a python program to convert two decimal numbers (A and B) to binary numbers. You should generate B complement signal (flip all the bits of Input B,
Create a program that ask to input two users and the result will vary on their...
Create a program that ask to input two users and the result will vary on their name with similar digits. In a game of F.L.A.M.E.S , it will count and repeat depends on their name that has a similar digit. For an Example (JOE RIZAL) and (JACKLYN BRACKEN) - JOE RIZAL has - 5 similar digits , while JACKLYN BRACKEN has 6 similar digits so a total of 11. F - Friends - 1,7 L - Lover - 2,8 A...
Using the Python program: a/ Write a program that adds all numbers from 1 to 100...
Using the Python program: a/ Write a program that adds all numbers from 1 to 100 to a list (in order). Then remove the multiples of 3 from the list. Print the remaining values. b/ Write a program that initializes a list with ten random integers from 1 to 100. Then remove the multiples of 3 and 5 from the list. Print the remaining values. Please show your work and explain. Thanks
use java Write a program that, given two binary numbers represented as strings, prints their sum...
use java Write a program that, given two binary numbers represented as strings, prints their sum in binary. The binary strings are comma separated, two per line. The final answer should not have any leading zeroes. In case the answer is zero, just print one zero i.e. 0 Input: Your program should read lines from standard input. Each line contains two binary strings, separated by a comma and no spaces. Output: For each pair of binary numbers print to standard...
Binary Tree Create a binary search tree using the given numbers in the order they’re presented....
Binary Tree Create a binary search tree using the given numbers in the order they’re presented. State if the resulting tree is FULL and/or BALANCED. 37, 20, 18, 56, 40, 42, 12, 5, 6, 77, 20, 54
Write functions: i) One that prompts a user for 2 numbers. ii) Adds the two numbers...
Write functions: i) One that prompts a user for 2 numbers. ii) Adds the two numbers if they are even iii) Multiplies the two numbers if they are odd iv) Displays the appropriate output to the user You are writing 4 functions and calling them to test functionality. RUN in IDLE
Task 1 Write a program that adds the three numbers stored in data registers at 0x20,...
Task 1 Write a program that adds the three numbers stored in data registers at 0x20, 0x30, and 0x40 and places the sum in data register at 0x50 task 4 Modify the program in Task1, so the program will run in infinite loop by using these following functions: GOTO function BRA function CALL function Simulate your program in PIC18 IDE Simulator and attach a screenshot of your simulation while the program is running.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT