;;; File: lab6b.asm .ORIG x3000 ReadString LEA R0, Prompt PUTS ; Display a prompt requesting input LD R1, BuffLen ; Set R1 to length of input buffer LEA R2, BuffPtr ; Set R2 to address of input buffer in memory BRnzp ReadCore ; Goto the core input code BuffPtr .BLKW 8 ; The memory reserved for the input buffer Prompt .STRINGZ "Enter a number: " ; The prompt string BuffLen .FILL 8 ; The length of the input buffer ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Insert your code for ReadCore from part 1 here. ;;; Your code from part 1 here ends here. ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ProcessInput LEA R2, BuffPtr ; Set R2 to address of buffer in memory BRnzp ProcessInputCore ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Insert your code for ProcessInputCore from part 2 here. ;;; Your code from part 2 here ends here. ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ParseDecimal LD R5, NegZERO LD R6, NegNINE AND R3, R3, #0 ; Set R3 to 0 DecimalLoop LDR R4, R2, #0 ; Put next digit into R4 BRz DoneParsingDecimal ; If it is the null terminator, done parsing ;; Confirm that it is a valid digit ADD R0, R4, R5 ; Compare to "0" BRn ParseError ; If less than "0", not a digit ADD R0, R4, R6 ; Compare to "9" BRp ParseError ; If greater than "9", not a digit ;; Multiply R3 by 10 ADD R7, R3, R3 ; R7 = 2*R3 ADD R3, R7, R7 ; R3 = 4*R3 ADD R3, R3, R3 ; R3 = 8*R3 ADD R3, R3, R7 ; R3 = 8*R3 + 2*R3 = 10*R3 ;; Add new digit to R3 ADD R4, R4, R5 ; Make binary ADD R3, R3, R4 ; Add new digit ADD R2, R2, #1 ; Increment memory pointer BRnzp DecimalLoop DoneParsingDecimal ;; Check if we need to negate the result for the minus sign ADD R1, R1, #0 ; If R1 is not -1, skip negation of R3 BRzp NotNegativeDecimal NOT R3, R3 ADD R3, R3, #1 ; Negate R3 NotNegativeDecimal BRnzp PrintResult NegZero .FILL -48 ; Negative ASCII "0" NegNine .FILL -57 ; Negative ASCII "9" ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Write your code for part 4 here. ParseHex BRnzp PrintResult ;;; Your code for part 4 here ends here. ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ParseError LEA R0, ErrorStr PUTS ; Output the error string BRnzp ReadString ErrorStr .STRINGZ "Invalid number format.\n" ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Write your code for part 3 here. ;;; Your code for part 3 here ends here. ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; .END