Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .section .init
- .globl _start
- _start:
- b main
- .section .text
- main:
- mov sp, #0x8000 // SP
- bl EnableJTAG // JTAG
- bl InitUART // UART
- ldr r0, =creator // Chris, Jas, Alvin
- mov r1, #54 // Allocates bytes
- bl WriteStringUART // Call print
- test:
- ldr r0, =tests
- mov r1, #34
- bl WriteStringUART
- b parkingPrompt
- parkingPrompt:
- ldr r0, =prompt // Asks user for hours
- mov r1, #96 // Allocates bytes
- bl WriteStringUART // Call Print
- ldr r0, =userInput // Buffer for user input
- mov r1, #256
- bl ReadLineUART // Input in r0
- // Compare bits //
- cmp r0, #1 // Checks if user input == 1 byte
- blt printInputError // Input < 1
- beq firstDigit // Go to first digit
- cmp r0, #2 // Checks if user input == 2 bytes
- beq secondDigit // Go to second digit
- cmp r0, #3 // Checks if user input == 3 bytes
- beq thirdDigit // Go to third digit
- cmp r0, #4 // Checks if user input == 4 bytes
- beq fourthDigit // Go to fourth digit
- cmp r0, #5 // Checks if user input == 5 bytes
- bge printBoundError // Out of bound error
- printInputError:
- ldr r0, =inputError // Error message for invalid characters
- mov r1, #77 // Allocates bytes
- bl WriteStringUART // Prints
- b parkingPrompt
- printBoundError:
- ldr r0, =boundError // Error message for out of bound integers
- mov r1, #51 // Allocates bytes
- bl WriteStringUART // Prints
- b parkingPrompt
- firstDigit:
- ldr r0, =userInput // Address of Buffer
- ldrb r1, [r0, #0] // Loading the first character
- cmp r1, #81 // Compares the one digit to ASCII value for q
- beq ExitProgram
- cmp r1, #113 // Compares the one digit to ASCII value for Q
- beq ExitProgram
- cmp r1, #49 // Compares r1 to 1
- blt printInputError
- cmp r1, #57 // Compares r1 to 9
- bgt printInputError
- b storeOneNumber
- secondDigit:
- ldr r0, =userInput // Address of Buffer
- ldrb r1, [r0, #0] // Loading the first character onto r1
- cmp r1, #50 // Checking if the first character is greater than 2
- bgt printInputError // Branch to error if it is greater than 2
- cmp r1, #48 // Compare to see if the input is a number and not other characters
- blt printInputError
- ldr r0, =userInput // Address of the buffer
- ldrb r1, [r0, #1] // Loading the second character onto r1
- cmp r1, #57 // Comparing to see if the second digit is a ascii character greater than 9
- bgt printInputError // Branch to an error message because this shows the byte was a non-number character
- cmp r1, #48 // Comparing to see if the second digit is a ascii character less than 0
- blt printInputError // Branch to error message
- b storeTwoNumber
- thirdDigit:
- b test
- fourthDigit:
- b test
- storeOneNumber:
- ldr r0, =userInput // Loading Buffer
- ldrb r1, [r0, #0] // Loading the byte onto r1
- ldr r0, =rawIntBuffer // Loading the integer buffer
- sub r1, r1, #48 // Subtracting 48 to convert from ASCII to int
- strb r1, [r0, #0] // Storing the integer byte onto r1
- b calcOneDigit
- storeTwoNumber:
- ldr r0, =userInput
- ldrb r4, [r0, #0]
- sub r4, r4, #48
- ldr r0, =userInput
- ldrb r10, [r0, #1]
- sub r10, r10, #48
- bl timesTen
- calcOneDigit:
- ldr r0, =rawIntBuffer // Loading the int onto the r0
- ldrb r4, [r0, #0] // Loading the first byte
- cmp r4, r5 // Comparing if my value is lower than the current min
- blt setMin
- cmp r4, r6 // Comparing if my value is higher than the current max
- bgt setMax
- b continue
- continue:
- cmp r4, #2 // Comparing to see if it less than or equal to two
- ble twoHourParking
- cmp r4, #20 // Comparing to see if it is more than the max parking amount
- bgt maxParking
- add r7, r7, #1 // Incrementing the counter for total number of customers
- sub r12, r4, #2 // Subtracting 2 from the total number of hours parked to calculate price
- mov r4, #0 // Setting the incremental counter back to 0
- mov r9, #0
- b calcAfterDecSet
- calcBefore:
- add r4, r4, #1 // Incrementing the counter
- add r11, r11, #1 // Adding 1 to the before the decimal value each iteration
- b calcBeforeDecSet
- calcAfter:
- add r4, r4, #1 // Incrementing the counter
- add r9, r9, #5 // Adding 5 to r9 each iteration
- b calcAfterDecSet
- calcAfterDecSet:
- cmp r12, r4 // Comparing the number of hours - 2 and the counter
- bgt calcAfter
- mov r4, #0 // Resetting the counter to 0
- cmp r9, #5 // Checking to see if r9 is not equal to 5
- bne split
- b calcBeforeDecSet
- calcBeforeDecSet:
- cmp r12, r4 // Comparing the number of hours - 2 and the counter
- bgt calcBefore
- mov r4, #0 // Resetting the counter to 0
- add r11, r11, #5 // Adding $5 for the first two hours of parking
- cmp r11, #9 // Comparing r11 and 9
- bgt splitBeforeDigit
- b printPrice
- setMin:
- mov r5, r4 // Setting the min register to the current min
- cmp r4, r6
- bgt setMax
- b continue
- setMax:
- mov r6, r4 // Setting the max register to the current max
- b continue
- maxParking:
- ldr r0, =rawIntBuffer // loading the int buffer
- mov r1, #33 // setting r1 to the price of the parking
- add r8, r8, r1 // Incrementing the total amount of money made
- add r7, r7, #1 // Incrementing the total number of people
- twoHourParking:
- ldr r0, =rawIntBuffer
- mov r1, #5
- add r8, r8, r1 // Incrementing the total amount spend counter
- add r1, r1, #48
- strb r1, [r0]
- mov r1, #33
- strb r1, [r0, #1]
- b printOneD
- timesTen:
- split:
- ldr r0, =buffer // Loading the buffer
- str r9, [r0] // Storing r9 onto the buffer
- ldrb r9, [r0, #1] // Loading on the second bit onto r9
- ldrb r11, [r0, #0] // Loading the first bit onto r11 and using this as a carryout later on
- b calcBeforeDecSet
- splitBeforeDigit:
- ldr r0, =buffer // Loading the buffer
- str r11, [r0] // Storing r9 onto the buffer
- ldrb r11, [r0, #1] // Loading on the second bit onto r11
- ldrb r10, [r0, #0] // Loading the first bit onto r11 and using this as a carryout later on
- // sub r11, r11, #48 // Might have to subtract 48 to make it back to int so we can use it in the before dec calculations /////////////////////////////////////
- b printPrice
- printPrice:
- ldr r0, =dollar
- mov r1, #1
- bl WriteStringUART
- add r10, r10, #48
- ldr r0, =printValue
- strb r10, [r0, #0]
- ldr r0, =printValue
- mov r1, #1
- bl WriteStringUART
- add r11, r11, #48
- ldr r0, =printValue
- strb r11, [r0, #0]
- ldr r0, =printValue
- mov r1, #1
- bl WriteStringUART
- ldr r0, =decimal
- mov r1, #1
- bl WriteStringUART
- add r9, r9, #48
- ldr r0, =printValue
- strb r9, [r0, #0]
- ldr r0, =printValue
- mov r1, #1
- bl WriteStringUART
- mov r10, #0
- mov r9, #0
- mov r11, #0
- printOneD:
- ldr r0, =dollar
- mov r1, #1
- bl WriteStringUART
- ldr r0, =rawIntBuffer
- mov r1, #1
- bl WriteStringUART
- add r7, r7, #1
- b parkingPrompt
- .section .data
- haltLoop$:
- b haltLoop$ // End
- ExitProgram:
- ldr r0, =Terminate
- mov r1, #18
- bl WriteStringUART
- // Buffers //
- rawIntBuffer:
- .rept 256
- .byte 0
- .endr
- buffer:
- .rept 256
- .byte 0
- .endr
- userInput:
- .rept 256
- .byte 0
- .endr
- printValue:
- .byte 0
- // Strings //
- tests:
- .ascii "\n\rthis is some random stuf to test" // 34
- decimal:
- .ascii "." // 1 Characters
- dollar:
- .ascii "$" // 1 Characters
- Terminate:
- .ascii "\n\rQuitting Program" // 18 Characters
- prompt:
- .ascii "\n\rPlease enter the number of parking hours for the customer. Press -1 for Summary or q to exit\n\r" // 96 Characters
- creator:
- .ascii "\n\rCreated by: Chris Chau, Jaskaran Sidhu, Alvin Cheung" // 54 Characters
- inputError:
- .ascii "\n\rInvalid Number! The number should be between 1 and 24 or -1 for the summary" // 77 Characters
- boundError:
- .ascii "\n\rNumber can only be between 1-24 or -1 for summary" // 51 Characters
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement