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
- mov r7, #0
- parkingPrompt:
- mov r4, #0
- mov r9, #0
- mov r10, #0
- mov r11, #0
- mov r3, #0
- 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] // 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
- ldrb r1, [r0, #0]
- cmp r1, #45
- beq checkNextDigit
- 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
- ldr r0, =userInput // Address of Buffer
- ldrb r1, [r0, #0] // Loading the first character onto r1
- cmp r1, #48 // Compare to see if the input is a number and not other characters
- blt printInputError
- cmp r1, #50 // Checking if the first character is greater than 2
- bgt printInputError // Branch to error if it is greater than 2
- beq twoDigitCheck // Branch to check if its less than 24
- b storeTwoNumber
- twoDigitCheck:
- ldr r0, =userInput
- ldrb r1, [r0, #1]
- cmp r1, #52
- bgt printInputError
- b storeTwoNumber
- thirdDigit:
- ldr r0, =userInput
- ldrb r1, [r0, #1]
- cmp r1, #46
- bne printInputError
- ldr r0, =userInput
- ldrb r1, [r0, #0]
- cmp r1, #49 // Compares r1 to 1
- blt printInputError
- cmp r1, #57 // Compares r1 to 9
- bgt printInputError
- ldr r0, =userInput
- ldrb r1, [r0, #3]
- cmp r1, #57
- beq incrementTwoDigit
- cmp r1, #48
- beq storeOneNumber
- b increment
- fourthDigit:
- ldr r0, =userInput
- ldrb r1, [r0, #2]
- cmp r1, #46
- bne printInputError
- ldr r0, =userInput
- ldrb r1, [r0, #1]
- cmp r1, #48 // Compares r1 to 0
- blt printInputError
- cmp r1, #57 // Compares r1 to 9
- bgt printInputError
- ldr r0, =userInput
- ldrb r1, [r0, #0]
- cmp r1, #49 // Compares r1 to 1
- blt printInputError
- cmp r1, #50 // Compares r1 to 9
- bgt printInputError
- beq fourByteCheck
- ldr r0, =userInput
- ldrb r1, [r0, #3]
- cmp r1, #48
- beq storeTwoNumber
- bgt incrementFourByte
- fourByteCheck:
- ldr r0, =userInput
- ldrb r1, [r0, #1]
- cmp r1, #52
- bgt printInputError
- ldr r0, =userInput
- ldrb r1, [r0, #3]
- cmp r1, #48
- beq storeTwoNumber
- bgt incrementFourByte
- incrementFourByte:
- ldr r0, =userInput
- ldrb r1, [r0, #1]
- cmp r1, #57
- beq doubleIncrement
- ldr r0, =userInput // Loading Buffer
- ldrb r10, [r0, #1] // Loading the byte onto r1
- sub r10, r10, #47 // Subtracting 47 to convert from ASCII to int that is being incremented
- ldr r0, =userInput // Loading the integer buffer
- ldrb r4, [r0, #0] // Storing the integer byte onto r4
- sub r4, r4, #48
- b timesTen
- doubleIncrement:
- mov r4, #20
- b calcTwoDigit
- increment:
- ldr r0, =userInput // Loading Buffer
- ldrb r1, [r0, #0] // Loading the byte onto r1
- ldr r0, =rawIntBuffer // Loading the integer buffer
- sub r1, r1, #47 // Subtracting 48 to convert from ASCII to int
- strb r1, [r0, #0] // Storing the integer byte onto r1
- b calcOneDigit
- incrementTwoDigit:
- mov r4, #10
- b calcTwoDigit
- checkNextDigit:
- mov r4, #0
- ldr r0, =userInput
- ldrb r1, [r0, #1]
- cmp r1, #49
- beq people
- 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
- ldr r0, =userInput // Address of Buffer
- ldrb r1, [r0, #0] // Loading the first character onto r1
- cmp r1, #48 // Compare to see if the input is a number and not other characters
- blt printInputError
- cmp r1, #50 // Checking if the first character is greater than 2
- bgt printInputError // Branch to error if it is greater than 2
- beq twoDigitCheck // Branch to check if its less than 24
- b storeTwoNumber
- 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
- b 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
- calcTwoDigit:
- 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:
- add r12, r12, r4
- 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
- sub r3, 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 r3, 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 r3, 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
- mov r10, #0
- 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 // Comparing the current amount of hours and the previous max
- bgt setMax
- b continue
- setMax:
- mov r6, r4 // Setting the max register to the current max
- b continue
- maxParking:
- add r8, r8, r1 // Incrementing the total amount of money made
- add r7, r7, #1 // Incrementing the total number of people
- ldr r0, =dollar
- mov r1, #1
- bl WriteStringUART
- mov r4, #51
- ldr r0, =printValue
- strb r4, [r0]
- ldr r0, =printValue
- mov r1, #1
- bl WriteStringUART
- mov r4, #51
- ldr r0, =printValue
- strb r4, [r0]
- ldr r0, =printValue
- mov r1, #1
- bl WriteStringUART
- b parkingPrompt
- 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
- splitPeople:
- sub r7, r7, #10
- add r4, r4, #1
- people:
- cmp r7, #9
- bgt splitPeople
- ldr r0, =customers
- mov r1, #29
- bl WriteStringUART
- add r4, r4, #48
- ldr r0, =printValue
- strb r4, [r0, #0]
- ldr r0, =printValue
- mov r1, #1
- bl WriteStringUART
- sub r4, r4, #48
- add r7, r7, #48
- ldr r0, =printValue
- strb r7, [r0, #0]
- ldr r0, =printValue
- mov r1, #1
- bl WriteStringUART
- sub r7, r7, #48
- b resetPeople
- resetPeople:
- mov r2, #0
- add r2, r4, r4
- add r2, r2, r2
- add r2, r2, r2
- add r2, r2, r4
- add r4, r2, r4
- mov r2, #0
- add r7, r7, r4
- mov r4, #0
- b chargedPrint
- splitCharged:
- sub r8, r8, #10
- add r4, r4, #1
- chargedPrint:
- cmp r8, #9
- bgt splitCharged
- ldr r0, =charged
- mov r1, #38
- bl WriteStringUART
- ldr r0, =dollar
- mov r1, #1
- bl WriteStringUART
- add r4, r4, #48
- ldr r0, =printValue
- strb r4, [r0, #0]
- ldr r0, =printValue
- mov r1, #1
- bl WriteStringUART
- mov r4, #0
- add r8, r8, #48
- ldr r0, =printValue
- strb r8, [r0, #0]
- ldr r0, =printValue
- mov r1, #1
- bl WriteStringUART
- sub r8, r8, #48
- ldr r0, =decimal
- mov r1, #1
- bl WriteStringUART
- b printMinimum
- splitMin:
- sub r5, r5, #10
- add r4, r4, #1
- printMinimum:
- cmp r5, #9
- bgt splitMin
- ldr r0, =minPrint
- mov r1, #27
- bl WriteStringUART
- add r4, r4, #48
- ldr r0, =printValue
- strb r4, [r0, #0]
- ldr r0, =printValue
- mov r1, #1
- bl WriteStringUART
- sub r4, r4, #48
- add r5, r5, #48
- ldr r0, =printValue
- strb r5, [r0, #0]
- ldr r0, =printValue
- mov r1, #1
- bl WriteStringUART
- sub r5, r5, #48
- b resetMin
- resetMin:
- mov r2, #0
- add r2, r4, r4
- add r2, r2, r2
- add r2, r2, r2
- add r2, r2, r4
- add r4, r2, r4
- mov r2, #0
- add r5, r5, r4
- mov r4, #0
- b printMaximum
- splitMax:
- sub r6, r6, #10
- add r4, r4, #1
- printMaximum:
- cmp r6, #9
- bgt splitMax
- ldr r0, =maxPrint
- mov r1, #27
- bl WriteStringUART
- add r4, r4, #48
- ldr r0, =printValue
- strb r4, [r0, #0]
- ldr r0, =printValue
- mov r1, #1
- bl WriteStringUART
- sub r4, r4, #48
- add r6, r6, #48
- ldr r0, =printValue
- strb r6, [r0, #0]
- ldr r0, =printValue
- mov r1, #1
- bl WriteStringUART
- sub r6, r6, #48
- b resetMax
- resetMax:
- mov r2, #0
- add r2, r4, r4
- add r2, r2, r2
- add r2, r2, r2
- add r2, r2, r4
- add r4, r2, r4
- mov r2, #0
- add r6, r6, r4
- mov r4, #0
- b setAverage
- setAverage:
- ldr r0, =averagePrint
- mov r1, #27
- bl WriteStringUART
- udiv r2, r12, r7
- cmp r2, #9
- bgt splitSetAverage
- b printAverage
- splitAverage:
- sub r2, r2, #10
- add r4, r4, #1
- splitSetAverage:
- cmp r2, #9
- bgt splitAverage
- b printAverage
- printAverage:
- add r4, r4, #48
- ldr r0, =printValue
- strb r4, [r0, #0]
- ldr r0, =printValue
- mov r1, #1
- bl WriteStringUART
- add r2, r2, #48
- ldr r0, =printValue
- strb r2, [r0, #0]
- ldr r0, =printValue
- mov r1, #1
- bl WriteStringUART
- mov r2, #0
- mov r4, #0
- timesTen:
- mov r2, #0
- add r2, r4, r4
- add r2, r2, r2
- add r2, r2, r2
- add r2, r2, r4
- add r4, r2, r4
- mov r2, #0
- add r4, r4, r10
- ldr r0, =rawIntBuffer
- str r4, [r0]
- b calcTwoDigit
- split:
- cmp r9, #10
- bge subTen
- b calcBeforeDecSet
- subTen:
- sub r9, r9, #10
- add r11, r11, #1
- b split
- splitBefore:
- sub r11, r11, #10
- add r10, r10, #1
- b splitBeforeDigit
- splitBeforeDigit:
- cmp r11, #10
- bge splitBefore
- 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
- add r7, r7, #1
- mov r10, #0
- mov r9, #0
- mov r11, #0
- b parkingPrompt
- 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 //
- customers:
- .ascii "\n\rTotal number of customers: " // 29 Characters
- charged:
- .ascii "\n\rTotal amount charged for customers: " // 38 Characters
- minPrint:
- .ascii "\n\rMinimum number of hours: " // 27 Characters
- maxPrint:
- .ascii "\n\rMaximum number of hours: " // 27 Characters
- averagePrint:
- .ascii "\n\rAverage number of hours: " // 27 Characters
- 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