Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .ORIG x3000
- AND R0, R0, #0 ;initialize all registers to 0, except for R7
- AND R1, R1, #0
- AND R2, R2, #0
- AND R3, R3, #0
- AND R4, R4, #0
- AND R5, R5, #0
- AND R6, R6, #0
- LD R1, User_Char ;load variables
- LD R2, This_Digit
- LD R3, Neg_Flag
- LD R4, User_Int
- LEA R0, STARTPROMPT ;print welcome message
- PUTS
- GET_USER_CHAR AND R0, R0, #0 ;clear R0 for GETC
- GETC
- AND R0, R0, #0
- BRzp XCHECK
- ADD R3, R3, #1 ;Neg_Flag=1
- BR GET_USER_CHAR
- XCHECK ADD R1, R1, R0
- ADD R1, R1, #-16 ;Subtract 88 (X) from ASCII value in R1
- ADD R1, R1, #-16
- ADD R1, R1, #-16
- ADD R1, R1, #-16
- ADD R1, R1, #-16
- ADD R1, R1, #-8
- BRz GOODBYE ;Exit the program if entered character was X
- AND R1, R1, #0 ;Subtract 12 (Newline) from ASCII value in R1
- ADD R1, R1, R0
- ADD R1, R1, #-12
- BRz 2SC_CHECKER ;Converts User_Int into 2SC if newline was entered
- AND R1, R1, #0
- ADD R1, R1, R0
- ADD R1, R1, #-16 ;Subtract "0" in ASCII from inputted value
- ADD R1, R1, #-16
- ADD R1, R1, #-16
- ADD R2, R1, #0 ;Update This_Digit
- ADD R4, R4, R4 ;User_Int*10
- ADD R4, R4, R4
- ADD R4, R4, R4
- ADD R4, R4, R4
- ADD R4, R4, R1 ;User_Int=User_Int*10+This_Digit
- BR GET_USER_CHAR
- 2SC_CHECKER ADD R3, R3, #0
- BRz PRINT_USER_INT_LOOP ;If Neg_Flag is not set, print the User_Int, otherwise take 2SC of User_Int
- NOT R4, R4
- ADD R4, R4, #1
- PRINT_USER_INT_LOOP AND R0, R0, #0
- ADD R0, R0, R5 ;Copy Counter_Offset to R0, check whether 16 iterations passed
- ADD R0, R0, #-15
- ADD R0, R0, #-1
- BRz GET_USER_CHAR ;program returns to prompt after printing inputted number in binary
- AND R0, R0, #0
- AND R6, R6, #0 ;clears previous bit mask retrieved from Mask_Array
- LEA R6, Mask_Array ;store Mask_Array pointer in R6
- ADD R6, R6, R5 ;add offset of Counter_Offset to Mask_Array pointer
- LDR R0, R6, #0 ;Load array value at new position into R0
- AND R0, R0, R4 ;Look at specific bit of User_Int
- BRnp ONE
- AND R0, R0, #0 ;Resets R0 to be used for printing 1
- LD R0, Zero
- PUTC
- BR INCREMENT
- ONE AND R0, R0, #0 ;Resets R0 to be used for printing 0
- LD R0, One
- PUTC
- INCREMENT ADD R5, R5, #1 ;Increments Counter_Offset
- BR PRINT_USER_INT_LOOP
- GOODBYE AND R0, R0, #0
- LEA R0, ENDPROMPT ; prints exit message
- PUTS
- HALT
- STARTPROMPT .STRINGZ "Welcome to the conversion program!"
- ENDPROMPT .STRINGZ "Bye. Have a great day."
- User_Char .FILL #0
- This_Digit .FILL #0
- Neg_Flag .FILL #0
- User_Int .FILL #0
- Mask_Array:
- .FILL b1000000000000000
- .FILL b0100000000000000
- .FILL b0010000000000000
- .FILL b0001000000000000
- .FILL b0000100000000000
- .FILL b0000010000000000
- .FILL b0000001000000000
- .FILL b0000000100000000
- .FILL b0000000010000000
- .FILL b0000000001000000
- .FILL b0000000000100000
- .FILL b0000000000010000
- .FILL b0000000000001000
- .FILL b0000000000000100
- .FILL b0000000000000010
- .FILL b0000000000000001
- .END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement