Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 12.75 KB | None | 0 0
  1. .section    .init
  2. .globl     _start
  3.  
  4. _start:
  5.     b       main
  6.  
  7.  
  8. .section .text
  9.  
  10. main:
  11.     mov     sp, #0x8000             // Initializing the stack pointer
  12.     bl      EnableJTAG          // Enable JTAG
  13.     bl      InitUART              // Initialize UART
  14.  
  15.     ldr r0,=Creator         //Address of creator names
  16.     mov r1, #56                  //Print 56 characters
  17.     bl  WriteStringUART
  18.  
  19.     mov r5, #0
  20.  
  21. PromptParkingAmount:
  22.     ldr r0, =ParkingPrompt          //Load prompt message
  23.     mov r1, #95                 //Print 95 characters
  24.     bl  WriteStringUART
  25.  
  26.     ldr r0, =Buffer
  27.     mov r1, #256
  28.     bl  ReadLineUART
  29.  
  30.     mov r7, r0                //Store the Buffer size so we can compare what we are saving
  31.  
  32.     cmp r0, #1
  33.     blt PromptParkingError
  34.     beq CheckOneDigit
  35.  
  36.     cmp r0, #2
  37.     beq CheckTwoDigit
  38.  
  39.     cmp r0, #3
  40.     beq CheckThreeDigit      //  If its 3 digit branch to print error messages
  41.     cmp r0, #4
  42.     bgt CheckFourDigit         //  if its greater than 4 digits branch to error messages
  43.  
  44.  
  45.  
  46.  
  47. CheckOneDigit:
  48.  
  49.     ldr r0, =Buffer             //Address of Buffer
  50.     ldrb    r1, [r0]                //Check first character
  51.  
  52.  
  53.     cmp r1, #81                 //compare to ASCII q
  54.     beq ExitProgram
  55.     cmp r1, #113                //compare to ASCII Q
  56.     beq ExitProgram
  57.     cmp r1, #49                 //Check if the number is between 1 and 9 for a one digit parking amount
  58.     blt PromptParkingError      //Branch to parking error if not
  59.     cmp r1, #57                 //compares to 9 if its greater than 9 then it has to be within 10-24
  60.     bgt PromptParkingError      //branch to parking Error
  61.  
  62.     b   storeNumber
  63.  
  64.  
  65. CheckTwoDigit:
  66.  
  67.     ldr r0, =Buffer             //Address of Buffer
  68.     ldrb    r1, [r0]                //Check 1st Character digits
  69.  
  70.  
  71.     cmp r1, #45                 // compare to the "-"
  72.     beq     CheckIfNegativeOne      //Checks if the input is a - symbol if it is branch to see if its -1
  73.     cmp r1, #49                 //compare to see if the input is between 1-2 for the 1st digit
  74.     beq CheckTwoDigitOneToNine  //if the number isn't it branches to error
  75.     cmp r1, #49                 //compare to see if the input is between 1-2 for the 1st digit
  76.     blt PromptParkingError2     //Go to negative/ Char Error Message
  77.     cmp r1, #50                 //compare the number to see if its 2
  78.     bgt PromptParkingError      //if it is greater than 2 branch to error
  79.  
  80.  
  81.     ldrb  r1, [r0, #1]          //Loads buffer of 2nd char
  82.  
  83.     cmp   r1, #48               //check if the value is between 0 and 4
  84.     blt   PromptParkingError    //branch less than to parking error if its less than 0
  85.     cmp   r1, #52               //Branch to Error Message if its greater than 4
  86.     bgt   PromptParkingError    //Branch if greater to Error
  87.  
  88.  
  89.     b   storeNumber             //branches to Store Number
  90.  
  91.  
  92. CheckTwoDigitOneToNine:
  93.  
  94.     ldr   r0, =Buffer         //load buffer address
  95.     ldrb  r1, [r0, #1]        //get 2nd character
  96.  
  97.     cmp   r1, #48             //compare to see if the value is 0
  98.     blt   PromptParkingError  // if its less than 0 quit
  99.     cmp   r1, #57             // compare to see if the value is greater than 9
  100.     bgt   PromptParkingError  //if it is go to parking error message
  101.  
  102.     b   storeNumber           // branch to Store Number
  103.  
  104.  
  105. CheckIfNegativeOne:
  106.  
  107.     ldr   r0, =Buffer         //Loads Buffer address
  108.     ldrb  r1, [r0, #1]        //Loads the 2nd Charater value
  109.  
  110.     cmp   r1, #49             //compare the 2nd digit to 1
  111.     beq   ParkingSummary       //if it is -1 then we branch to summary display if not branch to error
  112.  
  113.     b   PromptParkingError2
  114.  
  115.  
  116. CheckThreeDigit:
  117.  
  118.     ldr   r0, =Buffer       //loads the Buffer Address
  119.     ldrb  r1, [r0]          //Loads the 1st Char
  120.  
  121.     cmp   r1, #48           //compare char to 1
  122.     blt   PromptParkingError  //if less than branch to error message
  123.     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
  124.     bgt   PromptParkingError
  125.  
  126.     ldrb  r1, [r0,#1]
  127.     cmp   r1, #46
  128.     beq   DecimalIsTrue
  129.  
  130.     b   PromptParkingError
  131.  
  132.  
  133. DecimalIsTrue:
  134.  
  135.     ldr   r0, =Buffer
  136.     ldrb  r1, [r0,#2]
  137.  
  138.     cmp   r1, #48           //because you can have .0 value as error checks or anything
  139.     blt   PromptParkingError2
  140.     cmp   r1, #57
  141.     bgt   PromptParkingError
  142.  
  143.     b storeNumber
  144.  
  145.  
  146. CheckFourDigit:
  147.     ldr   r0, =Buffer       //load the Address of the buffer
  148.     ldrb  r1, [r0]          //load the first charater of the buffer
  149.  
  150.     cmp   r1, #49                       // compare to see if the digit value is 1
  151.     beq   FourDigitSecondDigitCheck    // if the digit is one then check if the 2nd value is between 1 to 9
  152.     cmp   r1, #50                       // check if the value is 2 if its check the 2nd digit between 0-4
  153.     bgt   PromptParkingError            // if its greater than 2 its go to error message
  154.  
  155.     ldrb  r1, [r0, #1]                  // load the value of the 2nd digit
  156.     cmp   r1, #48                       // compare the value to 0
  157.     blt   PromptParkingError            //if its less than quit to error message
  158.     cmp   r1, #52                       //compare to see if the number is between 0-4
  159.     b   CheckDecimalChar
  160.  
  161.  
  162.  
  163. FourDigitSecondDigitCheck:
  164.  
  165.     ldr   r0, =Buffer
  166.     ldrb  r1, [r0, #1]                   //load the 2nd character
  167.  
  168.     cmp   r1, #48                       //compares the 2nd digit to see if its
  169.     blt   PromptParkingError            //being less than zero it prints error messages
  170.     cmp   r1, #57                       //compare the 2nd digit to 1-9
  171.     bgt   PromptParkingError            //Branch to Error message
  172.  
  173.     b   CheckDecimalChar                //branch to check Decimal
  174.  
  175.  
  176. CheckDecimalChar:
  177.  
  178.     ldr   r0, =Buffer                 //load buffer
  179.     ldrb  r1, [r0, #2]
  180.  
  181.     cmp   r1, #46
  182.     beq   DecimalCheck
  183.     b   PromptParkingError
  184.  
  185.  
  186. DecimalCheck:
  187.  
  188.     ldr   r0, =Buffer
  189.     ldr   r1, [r0,#3]
  190.  
  191.     cmp   r1, #49
  192.     blt   PromptParkingError
  193.     cmp   r1, #57
  194.     bgt   PromptParkingError
  195.  
  196.     b   storeNumber
  197.  
  198.  
  199.  
  200.  
  201. storeNumber:
  202.  
  203.     cmp   r7, #1
  204.     beq   StoreOneDigit
  205.  
  206.     cmp   r7, #2
  207.     beq   StoreTwoDigit
  208.  
  209.     cmp   r7, #3
  210.     beq   StoreThreeDigit
  211.  
  212.     cmp   r7, #4
  213.     beq   StoreFourDigit
  214.  
  215.  
  216. StoreOneDigit:
  217.  
  218.     ldr r0, =Buffer
  219.     ldrb    r1, [r0]
  220.     ldr r0, =RawIntBuffer
  221.     sub r1, #48
  222.     strb    r1, [r0]
  223.  
  224.     b   CalculationsOneDigit
  225.  
  226.  
  227. CalculationsOneDigit:
  228.  
  229.     ldr r0, =RawIntBuffer
  230.     ldrb    r1, [r0]
  231.     cmp r1, #2
  232.     ble TwoHoursParking
  233.  cmp r1, #20
  234.  bgt MaxPaymentParking
  235.     sub r3, r1, #2
  236.     mov r10, #0
  237.     b   calcPriceBeforeDecSet
  238.  
  239.  
  240. calcPriceBeforeDecSet:
  241.     cmp r3, r10
  242.     bge calcPriceBeforeDec
  243.     mov r10, #0
  244.     add r10, r10, #5
  245.     add r10, r10, r11
  246.  
  247.     b   PrintTwoD
  248.  
  249. calcPriceAfterDecSet:
  250.     cmp r3, r10
  251.     bge calcPriceAfterDec
  252.     mov r10, #0
  253.     ldr r11, =CalcBuffer
  254.     mov r1, #256
  255.     cmp r11, #1
  256.     bgt carryOut
  257.     b   calcPriceBeforeDecSet
  258.  
  259.  
  260. carryOut:
  261.     ldrb    r12, [r11, #1]
  262.     ldrb    r11, [r11, #0]
  263.     sub r11, r11, #48
  264.     b   calcPriceBeforeDecSet
  265.  
  266.  
  267. calcPriceAfterDec:
  268.     add r11, r11, #5
  269.     add r10, r10, #1
  270.     b   calcPriceBeforeDecSet
  271.  
  272.  
  273. calcPriceBeforeDec:
  274.     add r10, r10, #1
  275.     b   calcPriceBeforeDecSet
  276.  
  277.  
  278.  
  279. /*
  280. OneDigitCalcs:
  281. cmp   r3, #0
  282. bgt   OneDLoop
  283.  
  284. add   r4, #5
  285. mov   r1, r4
  286. ldr   r0, =RawIntBuffer
  287. add   r1, #48
  288. strb  r1, [r0]
  289. b     PrintOneD
  290.  
  291.  
  292. OneDLoop:
  293.  
  294. add r4, r4          //add 1.5 into 1.5 for every hour
  295. sub r3, #1          //MINUS ONE FROM R3 TO CONTUINE LOOP until 0
  296.  
  297. b OneDigitCalcs
  298. */
  299.  
  300. TwoHoursParking:
  301.  
  302.     ldr   r0, =RawIntBuffer
  303.     mov   r1, #5
  304.     add   r1, #48
  305.     strb  r1, [r0]
  306.     mov   r1, #32
  307.     strb  r1, [r0, #1]
  308.  
  309.     b PrintOneD
  310.  
  311.  
  312. PrintOneD:
  313.  
  314.     ldr   r0, =DollarMessage
  315.     mov   r1, #2
  316.     bl    WriteStringUART
  317.  
  318.     ldr   r0, =RawIntBuffer
  319.     mov   r1, #2
  320.     bl    WriteStringUART
  321.  
  322.     add   r5, #1
  323.     b     PromptParkingAmount
  324.  
  325. /* setUpPreDec:
  326.  
  327.  
  328.  add r12, r10, #48
  329.  ldr r0, =printValue
  330.  strb  r12, [r0]
  331.  ldr r0, =printValue
  332.  mov r1, #1
  333.  bl  WriteStringUART
  334.  
  335.  
  336. setUpPostDec:
  337.  
  338.  add r12, r11, #48
  339.  ldr r0, =printValue
  340.  strb  r12, [r0]
  341.  ldr r0, =printValue
  342.  mov r1, #1
  343.  bl  WriteStringUART
  344.  
  345.  
  346. dec:
  347.  ldr r0, =Decimal
  348.  mov r1, #3
  349.  bl  WriteStringUART
  350.  
  351.  */
  352.  
  353. PrintTwoD:
  354.  /*
  355.  bl  setUpPreDec
  356.  bl  dec
  357.  bl  setUpPostDec
  358.  */
  359.  ldr   r0, =DollarMessage      // Prints out $
  360.     mov   r1, #2
  361.     bl    WriteStringUART
  362.  
  363.  add r12, #52
  364.  ldr r0, =printValue
  365.  strb  r12, [r0]
  366.  ldr r0, =printValue
  367.  mov r1, #1
  368.  bl  WriteStringUART
  369.  
  370.  ldr r0, =Decimal
  371.  mov r1, #3
  372.  bl  WriteStringUART
  373.  
  374.  add r12, #53
  375.  ldr r0, =printValue
  376.  strb r12, [r0]
  377.  ldr r0, =printValue
  378.  mov r1, #1
  379.  bl  WriteStringUART
  380.  
  381.  b PromptParkingAmount
  382. StoreTwoDigit:
  383.  
  384.     ldr   r0, =Buffer
  385.     ldrb  r1, [r0]
  386.     sub   r1, #48
  387.     mov   r2, #10
  388.     mul   r1, r2
  389.     ldrb  r2, [r0,#1]
  390.     sub   r2, #48
  391.     add   r1, r2
  392.  
  393.  
  394.  
  395.  
  396. /*
  397. OneDigitCalcs:
  398. cmp   r3, #0
  399. bgt   OneDLoop
  400. ldr r0,=RawIntBuffer
  401.     strb  r1, [r0]
  402.  
  403.     cmp   r1, #20
  404.     bgt   MaxPaymentParking
  405.     b     ParkingSummary        //testing purpose Delete after
  406. */
  407. MaxPaymentParking:
  408.  
  409.     ldr   r0, =RawIntBuffer
  410.     mov   r1, #33
  411.     mov   r5, r1
  412.     mov   r2, #0
  413.  
  414. SubtractTenLoop:
  415.     cmp   r1, #10
  416.     blo   EndSubtract
  417.     sub   r1, #10
  418.     add   r2, #1
  419.     b     SubtractTenLoop
  420.  
  421. EndSubtract:
  422.     mov   r8, r2                  //save the first digit
  423.     mov   r9, #10                 //move ten into r9
  424.     mul   r2, r9                  //multiply first digit by 10
  425.     sub   r5, r2                  //subtracat intial value to get 2nd digit
  426.     ldr   r0, =RawIntBuffer       //load buffer
  427.     add   r8, #48                 //get the ascci for the 1st digit
  428.     strb  r8, [r0]                //store into the buffer
  429.     add   r5, #48                 //2nd digit of into ascii
  430.     strb  r5, [r0, #1]            //store into buffer for printing purposes
  431.  
  432.     ldr   r0, =RawIntBuffer
  433.     mov   r1, #2
  434.     bl    WriteStringUART
  435.  
  436.     ldr   r0, =DollarMessage
  437.     mov   r1, #2
  438.     bl    WriteStringUART
  439.  
  440.     add   r5, #1
  441.     b     PromptParkingAmount
  442.  
  443.     //going to need to add more bytes to check the decimal vaues between 2.1 and 9.9
  444. StoreThreeDigit:
  445.  
  446.     ldr   r0, =Buffer               //Loads the address
  447.     ldrb  r1, [r0]                  //this only checks the 1st two digit as it doesn't matter for any hours less than 2
  448.     sub   r1, #48
  449.     cmp   r1, #2
  450.     ble   TwoHoursParking           //Branches to the two hour parking
  451.  
  452.     //Going to need to add MOre bytes to check the Decimal for anything less than 20
  453. StoreFourDigit:
  454.     ldr r0, =Buffer             //This only checks two digits as anything greater than 20 be it 20.1-24 is 33$
  455.     ldr r0, =Buffer
  456.     ldrb    r1, [r0]
  457.     sub     r1, #48
  458.     mov     r2, #10
  459.     mul     r1, r2
  460.     ldrb    r2, [r0,#1]
  461.     sub     r2, #48
  462.     add     r1, r2
  463.     ldr     r0, =RawIntBuffer
  464.     strb    r1, [r0]
  465.  
  466.     cmp     r1, #30
  467.     bgt     MaxPaymentParking
  468.  
  469.  
  470. PromptParkingError:
  471.  
  472.     ldr r0, =ParkingErrorMessage
  473.     mov r1, #74
  474.     bl  WriteStringUART
  475.     b   PromptParkingAmount
  476.  
  477. PromptParkingError2:
  478.  
  479.     ldr r0, =ParkingErrorMessage2
  480.     mov r1, #55
  481.     bl  WriteStringUART
  482.     b   PromptParkingAmount
  483.  
  484.  
  485. ParkingSummary:
  486. //Testing purposes printing message Delete Later
  487.  
  488.     ldr r0, =Test
  489.     mov r1, #15
  490.     bl  WriteStringUART
  491.     b   PromptParkingAmount
  492.  
  493. ExitProgram:
  494.  
  495.     ldr r0, =Terminate
  496.     mov r1, #19
  497.     bl  WriteStringUART
  498.  
  499.  
  500. haltLoop$:
  501.     b   haltLoop$           //End program
  502.  
  503.  
  504.  
  505. /*
  506.   DecimalToASCII:
  507.     cmp r6, r4              //Compare index to list length
  508.     bgt DisplayMedian
  509.  
  510.     ldr r0, =IntegerArray       //Address of the array of decimals
  511.     add r0, r6              //Offset to the current number to be displayed
  512.     ldrb    r1, [r0]            //Get the number
  513.  
  514.     cmp r1, #9              //Compare the number to 9
  515.     ble OneDigit            //if less or equal, 1 digit number
  516.     cmp r1, #99             //Compare the number to 99
  517.     ble TwoDigit            //if less or equal, 2 digit number
  518.  
  519.     ldr r0, =Buffer         //Address of buffer
  520.     mov r1, #49             //ASCII value of 1
  521.     strb    r1, [r0]            //put in buffer
  522.     mov r1, #48             //ASCII value of 0
  523.     strb    r1, [r0, #1]            //put 0 in buffer+1
  524.     strb    r1, [r0, #2]            //put 0 in buffer+2
  525.     mov r1, #32             //ASCII for space
  526.     strb    r1, [r0, #3]            //put space in buffer
  527.  
  528.     ldr r0, =Buffer         //Address of buffer. MAY BE REMOVED
  529.     mov r1, #4              //Print  characters
  530.     bl  WriteStringUART
  531.  
  532.     add r6, #1              //Add 1 to counter
  533.     b   DecimalToASCII          //Move to next number
  534.  
  535.  
  536.   */
  537.  
  538.  
  539. .section .data
  540.  
  541. Creator:
  542.     .ascii "\n\rCreated by: Alvin Cheung, Chris Chau, Jaskaran Sidhu"       //54
  543.  
  544. ParkingPrompt:
  545.     .ascii "\n\rPlease Enter the number of parking hours for the customer. Press -1 for Summary or q to exit " //95
  546.  
  547. ParkingErrorMessage:
  548.     .ascii "\n\rInvalid number! the number should be between 1 and 24 or -1 for summary\n "     //74
  549.  
  550. ParkingErrorMessage2:
  551.     .ascii "\n\r Number can only be between 1-24 or -1 for summary\n "      //55
  552.  
  553. DollarMessage:
  554.     .ascii " $"   //2
  555.  
  556. Decimal:
  557.     .ascii " . "    // 3
  558. Buffer:
  559.     .rept   256
  560.     .byte   0
  561.     .endr
  562.  
  563. RawIntBuffer:
  564.     .rept 256
  565.     .byte 0
  566.     .endr
  567.  
  568. CalcBuffer:
  569.     .rept   256
  570.     .byte 0
  571.     .endr
  572.  
  573. printValue:
  574.   .byte 0
  575.  
  576. Test:
  577.     .ascii  "\n\rNumber average"//size:15
  578.  
  579. Terminate:
  580.     .ascii   "\n\r Quitting Program"//19
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement