•

Check out our Community Blogs

Register and join over 40,000 other developers!

### Recent Blog Entries

• phi

I love this community !

• JackJames

hi i am jack i am seo expert jack james would love you to read new post

# Need help with multiple digits for calculator

assembly

This topic has been archived. This means that you cannot reply to this topic.
No replies to this topic

### #1 md001

md001

CC Lurker

• Just Joined
• 2 posts

Posted 15 December 2015 - 08:13 PM

This is the code i have so far. it has all of the functionality i want it to, except it only handles 1 digits. I need this program to handle 2 and 3 digit capacity, and im stuck.

```ORIG x3000 ; load the program here

; Request factor1 from the user

AND R0,R0,#0

; Call prompt subroutine and output PROMPT1

LEA R3,PROMPT1
JSR PMPTOUT

TRAP x20 ; Use GETC to retrieve user character entry into R0
TRAP x21 ; Echo the entered factor

; Convert factor1 to an integer
; Use R2 to convert ASCII factor1 to an integer, store in R4 when done

AND R2,R2,#0 ; Clear R2
JSR ATOI

LD R0,NewLine ; Go to a clean line for the next input
TRAP x21

; Request factor2 from user

AND R0,R0,#0

; Call prompt subroutine and output PROMPT2

LEA R3,PROMPT2
JSR PMPTOUT

TRAP x20 ; Use GETC to retrieve user character entry into R0
TRAP x21 ; Echo the entered factor

; Convert factor2 to an integer
; Use R2 to convert ASCII factor2 to an integer, store in R5 when done

AND R2,R2,#0 ; Clear R2
JSR ATOI

LD R0,NewLine ; Go to a clean line for the next input
TRAP x21

; Perform multiplication with MULT subroutine
; Registers R4 and R5 correctly contain two integer factors here.
; R6 contains the integer product.

JSR MULT

; Use prompt writing subroutine to announce result

LEA R3,RESULT
JSR PMPTOUT

; Display the result of the multiplication on a clean line

JSR ITOA
TRAP x21 ; Write the product to the display
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
TRAP x25 ; HALT the processor
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PMPTOUT ST R7,SaveR7
AND R0,R0,#0
TRAP x22 ; Call PUTS
LD R7,SaveR7
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Multiply subroutine
; Expects factor1 in R4 and factor2 in R5
; Returns the product in R6

MULT AND R6,R6,#0 ; Clear R6 to hold result of multiplication
BRp AGAIN
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Subroutine to convert ASCII character to an integer
; This routine uses R2 as a holding register for the correction
ATOI ST R3,SaveR3
AND R3,R3,#0 ; Clear R3
LD R3,ASCII ; Load ASCII correction into R3
NOT R3,R3 ; Form 1s complement
ADD R3,R3,#1 ; Form 2s complement
ADD R2,R2,R3 ; ACSII correction, R2 now contains integer for
; math operations
LD R3,SaveR3
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
ITOA ST R3,SaveR3
AND R0,R0,#0 ; Clear R0 for product display
AND R3,R3,#0 ; Clear R3 to ready ASCII correction
LD R3,ASCII ; Load ASCII correction into R3
ADD R0,R0,R3 ; Make integer an ASCII character for output
LD R3,SaveR3
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; MEMORY AREA

NewLine .FILL x000A
ASCII .FILL x0030
SaveR7 .FILL x0000
SaveR3 .FILL x0000
PROMPT1 .STRINGZ "Enter the first factor\n"
PROMPT2 .STRINGZ "Enter the second factor\n"
RESULT .STRINGZ "The product of the factors is :\n"

.END
; End of
```

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download