|
-
November 11th, 2005, 07:50 PM
#6
Re: convert decimal input to english text output
well here's the code i ended up with:
Code:
; Take sequence of ASCII digits typed by user, call ASCIItoBinary subroutine for conversion, push binary value onto
; stack.
.ORIG x3000
INPUT LEA R0,PROMPT ;load prompt
PUTS ;display prompt
GETC ;read number
OUT ;display number
BRnzp RangeCheck
PUSH LEA R1,ASCIIBUFF ;R1 points to string being
LD R2,MAX ;generated
VALUE ADD R3,R0,xFFF6 ;test for carriage return
BRz GOOD
ADD R2,R2,#0
BRz TooLarge
ADD R2,R2,#-1 ;read more digits
STR R0,R1,#0 ;store last character read
ADD R1,R1,#1
GETC
OUT ;echo
BRnzp VALUE
GOOD LEA R2,ASCIIBUFF
NOT R2,R2
ADD R2,R2,#1
ADD R1,R1,R2 ;R1 contains number of characters
JSR ASCIItoBinary
JSR PUSH
BRnzp INPUT
TooLarge GETC ;loop until return
OUT
ADD R3,R0,xFFF6
BRnp TooLarge
BRnzp INPUT
;ASCIItoBinary conversion
ASCIItoBinary AND R0,R0,#0 ;R0 contains result
ADD R1,R1,#0 ;test number of digits
BRz END ;no digits,terminate
LD R3,NEGOFF ;R3 gets xFFD0
LEA R2,ASCIIBUFF
ADD R2,R2,R1
ADD R2,R2,#-1 ;R2 points to ones place
LDR R4,R2,#0 ;load ones digit in R4
ADD R4,R4,R3 ;strip off ASCII template
ADD R0,R0,R4 ;add ones digit
ADD R1,R1,#-1
BRz DONE ;original number had one digit
ADD R2,R2,#-1 ;R2 points to tens place
LDR R4,R2,#0 ;R4 contains tens digit
ADD R4,R4,R3 ;strip off ASCII template
LEA R5,TENS ;tens values
ADD R5,R5,R4 ;R5 points to correct tens value
LDR R4,R5,#0
ADD R0,R0,R4 ;add tens value to total
ADD R1,R1,#-1
BRz DONE ;number consists of two digits
DONE RET
;routine to check that the magnitude of input is between 0 and 99.
RangeCheck LD R5,ZERO
ADD R4,R0,R5 ;R0 contais result being
BRp BAD ;checked
LD R5,NINETYNINE
ADD R4,R0,R5
BRn BAD
ADD R5,R5,0 ;R5 <- within range
RET
BAD ST R7,Save ;save R7
LEA R0,ERROR
PUTS ;display error msg
LD R7,Save
AND R5,R5,#0
ADD R5,R5,#1 ;R5 <- out of range
BRnzp INPUT
END HALT
PROMPT .FILL x000A
.STRINGZ "?"
MAX .FILL x0003
NEGOFF .FILL xFFD0
ASCIIBUFF .BLKW 4
TENS .FILL #0
.FILL #10
.FILL #20
.FILL #30
.FILL #40
.FILL #50
.FILL #60
.FILL #70
.FILL #80
.FILL #90
ZERO .FILL #0
NINETYNINE .FILL #99
Save .FILL x0000
ERROR .FILL x000A
.STRINGZ "Error: Number must be between 0 and 99."
.END
i still don't know how to make the array, and i'm also confused on converting binary into english text to be displayed (i'm assuming this is done through the array).... also, it reports that number is out of range no matter what the input is... any suggestions?
Last edited by caramel; November 11th, 2005 at 08:56 PM.
If you choke a smurf, what color does it turn?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|