Question

.Modify the following program so it can add two numbers between the values 0 and 9 The current program only handles one digit as the sum Your program must handle up to 9+9 as input and output up to 18 Here is the starter program ORIG x3000 ;begin at x3000 ; input two numbers IN input an integer character (ascii) TRAP 231 LD R3, HEXN30subtract x30 to get integer ADD RO, RO, R3 ADD R1, RO, x0move the first integer to register 1 IN input another integer [TRAP 23) ADD RO, RO, R3convert it to an integer add the numbers ADD R2, RO, R1 ;add the two integers ; print the results LEA RO, MESGload the address of the message string PUTS ADD RO, R2, x0 move the sum to RO, to be output LD R3, HEX30add 30 to integer to get integer character ADD RO, RO, R3 OUT PUTS outputs a string TRAP 221 ;display the sum TRAP 21) ;stop HALT. TRAP 25) ; data MESG .STRINGZ The sum of those two numbers is: HEXN30 FILL XFFDO-30 HEX HEX30 FILL x0030; 30 HEX END

; original codes provided as following

.ORIG x3000        ; begin at x3000

; input two numbers

IN                               ; input an integer character (ascii) {TRAP 23}

LD R3, HEXN30 ; subtract x30 to get integer

ADD R0, R0, R3

ADD R1, R0, x0 ; move the first integer to register 1

IN                               ; input another integer {TRAP 23}

ADD R0, R0, R3 ; convert it to an integer

; add the numbers

ADD R2, R0, R1 ; add the two integers

; print the results

LEA R0, MESG      ; load the address of the message string

PUTS                         ; "PUTS" outputs a string {TRAP 22}

ADD R0, R2, x0   ; move the sum to R0, to be output

LD R3, HEX30      ; add 30 to integer to get integer character

ADD R0, R0, R3

OUT                           ; display the sum {TRAP 21}

; stop

HALT       ; {TRAP 25}

; data

MESG .STRINGZ "The sum of those two numbers is: "

HEXN30 .FILL xFFD0 ; -30 HEX

HEX30 .FILL x0030 ; 30 HEX

.END

0 0
Add a comment Improve this question Transcribed image text
Answer #1

solution:

-------------------------------------------------------------------------------------------------------------------------------

Program : Program to add two double digit numbers .oria x3600 LEA RO, MESSAGE ;message PUTS ; Read first number LD R0, NEWLINE ;PROMPT! OUT OUT LEA R0, PROMPT! PUTS GETC OUT LD R6, M30 ADD RO, RO, R6 ADD RI, R0 , R0 ; R1 = 2xR0 ADD R2, R1, #0 ; copy R1 Into R2 ADD R2, R2, R2 ADD R2, R2, R2 ADD R2, R2, R1 GETC OUT ADD R0, RO, R6; convert to hex ADD R3, R2, R0 ; R3 = first decimal number ; Read input1 : convert char to hex ; Read input2 ; Read second number LEA RO, PROMPT2 :aet character one PUTS GETC OUT ADD RO, RO, R6 convert char to hex ADD R1, RO, R0R12xR0 ADD R2, R1, #0 ;copy R1 Into R2 ADD R2, R2, R2R2 4xRO ADD R2, R2, R2R28xRO GETC get character two

Add a comment
Know the answer?
Add Answer to:
; original codes provided as following .ORIG x3000        ; begin at x3000 ; input two numbers...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Part 2 (22 pts) .ORIG x3000 LEA R1, STRZ AND R2, R2, #0 LD R4, CHAR...

    Part 2 (22 pts) .ORIG x3000 LEA R1, STRZ AND R2, R2, #0 LD R4, CHAR REPEAT LDR R3, R1, #0 BRz FINISH   ;Branch to FINISH if the value of R3 is zero ADD R3, R3, R4 BRnp PASS   ;Branch to PASS if the value of R3 is positive or negative ADD R2, R2, #1 PASS ADD R1, R1, #1 BR REPEAT   ;Branch always to REPEAT FINISH ST R2, COUNT HALT CHAR .FILL xFF91 COUNT .FILL x0000 STRZ .STRINGZ "Hello...

  • I am writing a code for the LC3 Simulator. This is in assembly, I need assistance...

    I am writing a code for the LC3 Simulator. This is in assembly, I need assistance with the numbers 5-8. Thank you. ALU OPERATIONS 1. Compute the sum X +Y and place it at location x3102. 2. Compute X AND Y and place it at location x3103. 3. Compute X OR Y and place it at location x3104. 4. Compute NOT(X) and place it at location x3105. 5. Compute NOT(Y) and place it at location x3106. 6. Compute X +3...

  • LC3 stack (factorial) I need help in writing factorial in Lc3 language by using stack.. ; Begin ...

    LC3 stack (factorial) I need help in writing factorial in Lc3 language by using stack.. ; Begin reserved section: do not change ANYTHING in reserved section! .ORIG x3000 BR Main ; Parameter and result Param .FILL x0004 Result .BLKW 1 ; Constants Stack .FILL x4000 One .FILL #1 MinusOne .FILL #-1 ; End reserved section: do not change ANYTHING in reserved section! ;------------------------------------------------------------------------------- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; int Factorial(int N) ; Returns N! (must be a recursive function) ; Factorial ;__________________...

  • 2. Assume there are two 4-byte numbers stored in addresses begin with DATA and DATA2 (lower byte first): it is required to calculate the sum of the tw numbers. Please draw the flowchart to implement...

    2. Assume there are two 4-byte numbers stored in addresses begin with DATA and DATA2 (lower byte first): it is required to calculate the sum of the tw numbers. Please draw the flowchart to implement this task (can refer to the cod below) R0.#DATA 1 MAIN: MOV MOV R 1 , #DATA2 MOV R2,#0411 CLR C LOOP: MOV A, @Ro ADDC A. @R1 MoV @RO, A INC RO INC RI DJNZ R2. LOOP JC OTHER RET 2. Assume there are...

  • Write a machine language program to input two one-digit numbers ranging from 0 to 4 (using...

    Write a machine language program to input two one-digit numbers ranging from 0 to 4 (using the character input instruction), add them, and then output the single digit sum (using the character output instruction). Execute your program in the PEP/8 simulator. Example Input: 43 (this is the numbers 4 and 3. Remember, this is two ASCII characters when inputted into your program) Output: 7 (ASCII character 55dec)

  • Write a program that reads in two hexadecimal numbers from a file, hex.dat, and prints out...

    Write a program that reads in two hexadecimal numbers from a file, hex.dat, and prints out the sum of the two numbers in hexadecimal. (As noted in class, first do this without using a file and by reading using the cin > > command) From Wikipedia: "In mathematics and computer science, hexadecimal (also base 16, or hex) is a positional numeral system with a radix, or base, of 16. It uses sixteen distinct symbols, most often the symbols 0-9 to...

  • 21 Write a program that asks the user to input the length and breadth of a...

    21 Write a program that asks the user to input the length and breadth of a soccer field, and then computes and returns the number of square meters of grass required to cover the field The formula for the area is the product of length and breadth (5) 22 The following program uses the break statement to terminate an infinite while loop to print 5 numbers Rewrite the program to use a while loop to display numbers from 1 to...

  • 5) Define a function called remainder _is_even which receives two positive integer numbers as parameters: num...

    5) Define a function called remainder _is_even which receives two positive integer numbers as parameters: num and div. This function should return a boolean value. The value to be returned should be True if the remainder of dividing num by div is even and it should return False otherwise. As an example, the following code fragment: print (remainder_is_even(23,2)) should produce the output: False 6) Define a function first_last_repeated which receives as input parameter a string (orig) with at least one...

  • LC-3 Programming Help!! The Stack Protocol The following outline is the protocol for passing arguments to...

    LC-3 Programming Help!! The Stack Protocol The following outline is the protocol for passing arguments to a function and returning values. Everything is stored on the runtime stack so that space is used only when the function is executing. As a result the actual address of arguments and locals may change from call to call. However, the layout of the stack frame (activation record) is constant. Thus, the offests from the frame pointer (FP) to the parameters/locals are constant. All...

  • /*************************************************** Name: Date: Homework #7 Program name: HexUtilitySOLUTION Program description: Accepts hexadecimal numbers as input. Valid...

    /*************************************************** Name: Date: Homework #7 Program name: HexUtilitySOLUTION Program description: Accepts hexadecimal numbers as input. Valid input examples: F00D, 000a, 1010, FFFF, Goodbye, BYE Enter BYE (case insensitive) to exit the program. ****************************************************/ import java.util.Scanner; public class HexUtilitySOLUTION { public static void main(String[] args) { // Maximum length of input string final byte INPUT_LENGTH = 4; String userInput = ""; // Initialize to null string Scanner input = new Scanner(System.in); // Process the inputs until BYE is entered do {...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT