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 // Initializing the stack pointer
- bl EnableJTAG // Enable JTAG
- bl InitUART // Initialize UART
- ldr r0,=Creator //Address of creator names
- mov r1, #56 //Print 56 characters
- bl WriteStringUART
- mov r5, #0
- PromptParkingAmount:
- ldr r0, =ParkingPrompt //Load prompt message
- mov r1, #95 //Print 95 characters
- bl WriteStringUART
- ldr r0, =Buffer
- mov r1, #256
- bl ReadLineUART
- mov r7, r0 //Store the Buffer size so we can compare what we are saving
- cmp r0, #1
- blt PromptParkingError
- beq CheckOneDigit
- cmp r0, #2
- beq CheckTwoDigit
- cmp r0, #3
- beq CheckThreeDigit // If its 3 digit branch to print error messages
- cmp r0, #4
- bgt CheckFourDigit // if its greater than 4 digits branch to error messages
- CheckOneDigit:
- ldr r0, =Buffer //Address of Buffer
- ldrb r1, [r0] //Check first character
- cmp r1, #81 //compare to ASCII q
- beq ExitProgram
- cmp r1, #113 //compare to ASCII Q
- beq ExitProgram
- cmp r1, #49 //Check if the number is between 1 and 9 for a one digit parking amount
- blt PromptParkingError //Branch to parking error if not
- cmp r1, #57 //compares to 9 if its greater than 9 then it has to be within 10-24
- bgt PromptParkingError //branch to parking Error
- b storeNumber
- CheckTwoDigit:
- ldr r0, =Buffer //Address of Buffer
- ldrb r1, [r0] //Check 1st Character digits
- cmp r1, #45 // compare to the "-"
- beq CheckIfNegativeOne //Checks if the input is a - symbol if it is branch to see if its -1
- cmp r1, #49 //compare to see if the input is between 1-2 for the 1st digit
- beq CheckTwoDigitOneToNine //if the number isn't it branches to error
- cmp r1, #49 //compare to see if the input is between 1-2 for the 1st digit
- blt PromptParkingError2 //Go to negative/ Char Error Message
- cmp r1, #50 //compare the number to see if its 2
- bgt PromptParkingError //if it is greater than 2 branch to error
- ldrb r1, [r0, #1] //Loads buffer of 2nd char
- cmp r1, #48 //check if the value is between 0 and 4
- blt PromptParkingError //branch less than to parking error if its less than 0
- cmp r1, #52 //Branch to Error Message if its greater than 4
- bgt PromptParkingError //Branch if greater to Error
- b storeNumber //branches to Store Number
- CheckTwoDigitOneToNine:
- ldr r0, =Buffer //load buffer address
- ldrb r1, [r0, #1] //get 2nd character
- cmp r1, #48 //compare to see if the value is 0
- blt PromptParkingError // if its less than 0 quit
- cmp r1, #57 // compare to see if the value is greater than 9
- bgt PromptParkingError //if it is go to parking error message
- b storeNumber // branch to Store Number
- CheckIfNegativeOne:
- ldr r0, =Buffer //Loads Buffer address
- ldrb r1, [r0, #1] //Loads the 2nd Charater value
- cmp r1, #49 //compare the 2nd digit to 1
- beq ParkingSummary //if it is -1 then we branch to summary display if not branch to error
- b PromptParkingError2
- CheckThreeDigit:
- ldr r0, =Buffer //loads the Buffer Address
- ldrb r1, [r0] //Loads the 1st Char
- cmp r1, #48 //compare char to 1
- blt PromptParkingError //if less than branch to error message
- cmp r1, #57 //checks if the first digit is from 0-9 since u cna only do 0.1-9.9 hours within 3 digits
- bgt PromptParkingError
- ldrb r1, [r0,#1]
- cmp r1, #46
- beq DecimalIsTrue
- b PromptParkingError
- DecimalIsTrue:
- ldr r0, =Buffer
- ldrb r1, [r0,#2]
- cmp r1, #48 //because you can have .0 value as error checks or anything
- blt PromptParkingError2
- cmp r1, #57
- bgt PromptParkingError
- b storeNumber
- CheckFourDigit:
- ldr r0, =Buffer //load the Address of the buffer
- ldrb r1, [r0] //load the first charater of the buffer
- cmp r1, #49 // compare to see if the digit value is 1
- beq FourDigitSecondDigitCheck // if the digit is one then check if the 2nd value is between 1 to 9
- cmp r1, #50 // check if the value is 2 if its check the 2nd digit between 0-4
- bgt PromptParkingError // if its greater than 2 its go to error message
- ldrb r1, [r0, #1] // load the value of the 2nd digit
- cmp r1, #48 // compare the value to 0
- blt PromptParkingError //if its less than quit to error message
- cmp r1, #52 //compare to see if the number is between 0-4
- b CheckDecimalChar
- FourDigitSecondDigitCheck:
- ldr r0, =Buffer
- ldrb r1, [r0, #1] //load the 2nd character
- cmp r1, #48 //compares the 2nd digit to see if its
- blt PromptParkingError //being less than zero it prints error messages
- cmp r1, #57 //compare the 2nd digit to 1-9
- bgt PromptParkingError //Branch to Error message
- b CheckDecimalChar //branch to check Decimal
- CheckDecimalChar:
- ldr r0, =Buffer //load buffer
- ldrb r1, [r0, #2]
- cmp r1, #46
- beq DecimalCheck
- b PromptParkingError
- DecimalCheck:
- ldr r0, =Buffer
- ldr r1, [r0,#3]
- cmp r1, #49
- blt PromptParkingError
- cmp r1, #57
- bgt PromptParkingError
- b storeNumber
- storeNumber:
- cmp r7, #1
- beq StoreOneDigit
- cmp r7, #2
- beq StoreTwoDigit
- cmp r7, #3
- beq StoreThreeDigit
- cmp r7, #4
- beq StoreFourDigit
- StoreOneDigit:
- ldr r0, =Buffer
- ldrb r1, [r0]
- ldr r0, =RawIntBuffer
- sub r1, #48
- strb r1, [r0]
- b CalculationsOneDigit
- CalculationsOneDigit:
- ldr r0, =RawIntBuffer
- ldrb r1, [r0]
- cmp r1, #2
- ble TwoHoursParking
- cmp r1, #20
- bgt MaxPaymentParking
- sub r3, r1, #2
- mov r10, #0
- b calcPriceBeforeDecSet
- calcPriceBeforeDecSet:
- cmp r3, r10
- bge calcPriceBeforeDec
- mov r10, #0
- add r10, r10, #5
- add r10, r10, r11
- b PrintTwoD
- calcPriceAfterDecSet:
- cmp r3, r10
- bge calcPriceAfterDec
- mov r10, #0
- ldr r11, =CalcBuffer
- mov r1, #256
- cmp r11, #1
- bgt carryOut
- b calcPriceBeforeDecSet
- carryOut:
- ldrb r12, [r11, #1]
- ldrb r11, [r11, #0]
- sub r11, r11, #48
- b calcPriceBeforeDecSet
- calcPriceAfterDec:
- add r11, r11, #5
- add r10, r10, #1
- b calcPriceBeforeDecSet
- calcPriceBeforeDec:
- add r10, r10, #1
- b calcPriceBeforeDecSet
- /*
- OneDigitCalcs:
- cmp r3, #0
- bgt OneDLoop
- add r4, #5
- mov r1, r4
- ldr r0, =RawIntBuffer
- add r1, #48
- strb r1, [r0]
- b PrintOneD
- OneDLoop:
- add r4, r4 //add 1.5 into 1.5 for every hour
- sub r3, #1 //MINUS ONE FROM R3 TO CONTUINE LOOP until 0
- b OneDigitCalcs
- */
- TwoHoursParking:
- ldr r0, =RawIntBuffer
- mov r1, #5
- add r1, #48
- strb r1, [r0]
- mov r1, #32
- strb r1, [r0, #1]
- b PrintOneD
- PrintOneD:
- ldr r0, =DollarMessage
- mov r1, #2
- bl WriteStringUART
- ldr r0, =RawIntBuffer
- mov r1, #2
- bl WriteStringUART
- add r5, #1
- b PromptParkingAmount
- /* setUpPreDec:
- add r12, r10, #48
- ldr r0, =printValue
- strb r12, [r0]
- ldr r0, =printValue
- mov r1, #1
- bl WriteStringUART
- setUpPostDec:
- add r12, r11, #48
- ldr r0, =printValue
- strb r12, [r0]
- ldr r0, =printValue
- mov r1, #1
- bl WriteStringUART
- dec:
- ldr r0, =Decimal
- mov r1, #3
- bl WriteStringUART
- */
- PrintTwoD:
- /*
- bl setUpPreDec
- bl dec
- bl setUpPostDec
- */
- ldr r0, =DollarMessage // Prints out $
- mov r1, #2
- bl WriteStringUART
- add r12, #52
- ldr r0, =printValue
- strb r12, [r0]
- ldr r0, =printValue
- mov r1, #1
- bl WriteStringUART
- ldr r0, =Decimal
- mov r1, #3
- bl WriteStringUART
- add r12, #53
- ldr r0, =printValue
- strb r12, [r0]
- ldr r0, =printValue
- mov r1, #1
- bl WriteStringUART
- b PromptParkingAmount
- StoreTwoDigit:
- ldr r0, =Buffer
- ldrb r1, [r0]
- sub r1, #48
- mov r2, #10
- mul r1, r2
- ldrb r2, [r0,#1]
- sub r2, #48
- add r1, r2
- /*
- OneDigitCalcs:
- cmp r3, #0
- bgt OneDLoop
- ldr r0,=RawIntBuffer
- strb r1, [r0]
- cmp r1, #20
- bgt MaxPaymentParking
- b ParkingSummary //testing purpose Delete after
- */
- MaxPaymentParking:
- ldr r0, =RawIntBuffer
- mov r1, #33
- mov r5, r1
- mov r2, #0
- SubtractTenLoop:
- cmp r1, #10
- blo EndSubtract
- sub r1, #10
- add r2, #1
- b SubtractTenLoop
- EndSubtract:
- mov r8, r2 //save the first digit
- mov r9, #10 //move ten into r9
- mul r2, r9 //multiply first digit by 10
- sub r5, r2 //subtracat intial value to get 2nd digit
- ldr r0, =RawIntBuffer //load buffer
- add r8, #48 //get the ascci for the 1st digit
- strb r8, [r0] //store into the buffer
- add r5, #48 //2nd digit of into ascii
- strb r5, [r0, #1] //store into buffer for printing purposes
- ldr r0, =RawIntBuffer
- mov r1, #2
- bl WriteStringUART
- ldr r0, =DollarMessage
- mov r1, #2
- bl WriteStringUART
- add r5, #1
- b PromptParkingAmount
- //going to need to add more bytes to check the decimal vaues between 2.1 and 9.9
- StoreThreeDigit:
- ldr r0, =Buffer //Loads the address
- ldrb r1, [r0] //this only checks the 1st two digit as it doesn't matter for any hours less than 2
- sub r1, #48
- cmp r1, #2
- ble TwoHoursParking //Branches to the two hour parking
- //Going to need to add MOre bytes to check the Decimal for anything less than 20
- StoreFourDigit:
- ldr r0, =Buffer //This only checks two digits as anything greater than 20 be it 20.1-24 is 33$
- ldr r0, =Buffer
- ldrb r1, [r0]
- sub r1, #48
- mov r2, #10
- mul r1, r2
- ldrb r2, [r0,#1]
- sub r2, #48
- add r1, r2
- ldr r0, =RawIntBuffer
- strb r1, [r0]
- cmp r1, #30
- bgt MaxPaymentParking
- PromptParkingError:
- ldr r0, =ParkingErrorMessage
- mov r1, #74
- bl WriteStringUART
- b PromptParkingAmount
- PromptParkingError2:
- ldr r0, =ParkingErrorMessage2
- mov r1, #55
- bl WriteStringUART
- b PromptParkingAmount
- ParkingSummary:
- //Testing purposes printing message Delete Later
- ldr r0, =Test
- mov r1, #15
- bl WriteStringUART
- b PromptParkingAmount
- ExitProgram:
- ldr r0, =Terminate
- mov r1, #19
- bl WriteStringUART
- haltLoop$:
- b haltLoop$ //End program
- /*
- DecimalToASCII:
- cmp r6, r4 //Compare index to list length
- bgt DisplayMedian
- ldr r0, =IntegerArray //Address of the array of decimals
- add r0, r6 //Offset to the current number to be displayed
- ldrb r1, [r0] //Get the number
- cmp r1, #9 //Compare the number to 9
- ble OneDigit //if less or equal, 1 digit number
- cmp r1, #99 //Compare the number to 99
- ble TwoDigit //if less or equal, 2 digit number
- ldr r0, =Buffer //Address of buffer
- mov r1, #49 //ASCII value of 1
- strb r1, [r0] //put in buffer
- mov r1, #48 //ASCII value of 0
- strb r1, [r0, #1] //put 0 in buffer+1
- strb r1, [r0, #2] //put 0 in buffer+2
- mov r1, #32 //ASCII for space
- strb r1, [r0, #3] //put space in buffer
- ldr r0, =Buffer //Address of buffer. MAY BE REMOVED
- mov r1, #4 //Print characters
- bl WriteStringUART
- add r6, #1 //Add 1 to counter
- b DecimalToASCII //Move to next number
- */
- .section .data
- Creator:
- .ascii "\n\rCreated by: Alvin Cheung, Chris Chau, Jaskaran Sidhu" //54
- ParkingPrompt:
- .ascii "\n\rPlease Enter the number of parking hours for the customer. Press -1 for Summary or q to exit " //95
- ParkingErrorMessage:
- .ascii "\n\rInvalid number! the number should be between 1 and 24 or -1 for summary\n " //74
- ParkingErrorMessage2:
- .ascii "\n\r Number can only be between 1-24 or -1 for summary\n " //55
- DollarMessage:
- .ascii " $" //2
- Decimal:
- .ascii " . " // 3
- Buffer:
- .rept 256
- .byte 0
- .endr
- RawIntBuffer:
- .rept 256
- .byte 0
- .endr
- CalcBuffer:
- .rept 256
- .byte 0
- .endr
- printValue:
- .byte 0
- Test:
- .ascii "\n\rNumber average"//size:15
- Terminate:
- .ascii "\n\r Quitting Program"//19
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement