Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 11.04 KB | None | 0 0
  1. .section    .init
  2. .globl      _start
  3.  
  4. _start:
  5.  
  6.     b       main
  7.  
  8. .section    .text
  9.  
  10. main:
  11.  
  12.     mov     sp, #0x8000                     // SP
  13.     bl      EnableJTAG                      // JTAG
  14.     bl      InitUART                          // UART
  15.  
  16.  
  17.     ldr     r0, =creator                    // Chris, Jas, Alvin
  18.     mov     r1, #54                           // Allocates bytes
  19.     bl      WriteStringUART               // Call print
  20.  
  21.  
  22.  
  23.  
  24.  
  25. test:
  26.   ldr r0, =tests
  27.   mov r1, #34
  28.   bl WriteStringUART
  29.  
  30.   b parkingPrompt
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. parkingPrompt:
  39.  
  40.     mov r4, #0
  41.     mov r9, #0
  42.     mov r10, #0
  43.     mov r11, #0
  44.     mov r12, #0
  45.  
  46.     ldr     r0, =prompt                    // Asks user for hours
  47.     mov     r1, #96                          // Allocates bytes
  48.     bl      WriteStringUART              // Call Print
  49.  
  50.     ldr     r0, =userInput             // Buffer for user input
  51.     mov     r1, #256
  52.     bl      ReadLineUART                   // Input in r0
  53.  
  54.  
  55.     // Compare bits //
  56.  
  57.     cmp     r0, #1                           // Checks if user input == 1 byte
  58.     blt     printInputError              // Input < 1
  59.     beq     firstDigit                     // Go to first digit
  60.  
  61.     cmp     r0, #2                           // Checks if user input == 2 bytes
  62.     beq     secondDigit                    // Go to second digit
  63.  
  64.     cmp     r0, #3                         // Checks if user input == 3 bytes
  65.     beq     thirdDigit                     // Go to third digit
  66.  
  67.     cmp     r0, #4                           // Checks if user input == 4 bytes
  68.     beq     fourthDigit                    // Go to fourth digit
  69.  
  70.     cmp     r0, #5                           // Checks if user input == 5 bytes
  71.     bge     printBoundError              // Out of bound error
  72.  
  73.  
  74.  
  75. printInputError:
  76.  
  77.     ldr     r0, =inputError              // Error message for invalid characters
  78.     mov     r1, #77                          // Allocates bytes
  79.     bl      WriteStringUART              // Prints
  80.  
  81.   b parkingPrompt
  82.  
  83.  
  84.  
  85. printBoundError:
  86.  
  87.     ldr     r0, =boundError              // Error message for out of bound integers
  88.     mov     r1, #51                          // Allocates bytes
  89.     bl      WriteStringUART              // Prints
  90.  
  91.   b parkingPrompt
  92.  
  93.  
  94.  
  95. firstDigit:
  96.  
  97.   ldr r0, =userInput              // Address of Buffer
  98.   ldrb r1, [r0]                     // Loading the first character
  99.  
  100.   cmp r1, #81                   // Compares the one digit to ASCII value for q
  101.   beq ExitProgram
  102.  
  103.   cmp r1, #113                  // Compares the one digit to ASCII value for Q
  104.   beq ExitProgram
  105.  
  106.   cmp r1, #49                   // Compares r1 to 1
  107.   blt printInputError
  108.  
  109.   cmp r1, #57                  // Compares r1 to 9
  110.   bgt printInputError
  111.  
  112.   b storeOneNumber
  113.  
  114.  
  115.  
  116. secondDigit:
  117.  
  118.     ldr r0, =userInput                  // Address of the buffer
  119.     ldrb r1, [r0, #1]                       // Loading the second character onto r1
  120.  
  121.     cmp r1, #57                                 // Comparing to see if the second digit is a ascii character greater than 9
  122.     bgt printInputError                 // Branch to an error message because this shows the byte was a non-number character
  123.  
  124.     cmp r1, #48                                 // Comparing to see if the second digit is a ascii character less than 0
  125.     blt printInputError                 // Branch to error message
  126.  
  127.     ldr r0, =userInput                  // Address of Buffer
  128.     ldrb r1, [r0, #0]                       // Loading the first character onto r1
  129.  
  130.     cmp r1, #48                                 // Compare to see if the input is a number and not other characters
  131.     blt printInputError
  132.  
  133.     cmp r1, #50                                 // Checking if the first character is greater than 2
  134.     bgt printInputError                 // Branch to error if it is greater than 2
  135.     beq twoDigitCheck                       // Branch to check if its less than 24
  136.  
  137.     b storeTwoNumber
  138.  
  139.  
  140. twoDigitCheck:
  141.  
  142.     ldr r0, =userInput
  143.     ldrb r1, [r0, #1]
  144.  
  145.     cmp r1, #52
  146.     bgt printInputError
  147.     b storeTwoNumber
  148.  
  149.  
  150. thirdDigit:
  151.     ldr r0, =userInput
  152.     ldrb r1, [r0, #1]
  153.  
  154.     cmp r1, #46
  155.     bne printInputError
  156.  
  157.     ldr r0, =userInput
  158.     ldrb r1, [r0, #0]
  159.  
  160.     cmp r1, #49                     // Compares r1 to 1
  161.   blt printInputError
  162.  
  163.   cmp r1, #57                  // Compares r1 to 9
  164.   bgt printInputError
  165.  
  166.     ldr r0, =userInput
  167.     ldrb r1, [r0, #3]
  168.  
  169.     cmp r1, #57
  170.     beq incrementTwoDigit
  171.  
  172.     cmp r1, #48
  173.     beq storeOneNumber
  174.  
  175.     b increment
  176.  
  177.  
  178.  
  179. fourthDigit:
  180.     ldr r0, =userInput
  181.     ldrb r1, [r0, #2]
  182.  
  183.     cmp r1, #46
  184.     bne printInputError
  185.  
  186.  
  187.     ldr r0, =userInput
  188.     ldrb r1, [r0, #1]
  189.  
  190.     cmp r1, #48                     // Compares r1 to 0
  191.     blt printInputError
  192.  
  193.     cmp r1, #57                     // Compares r1 to 9
  194.     bgt printInputError
  195.  
  196.  
  197.     ldr r0, =userInput
  198.     ldrb r1, [r0, #0]
  199.  
  200.     cmp r1, #49                     // Compares r1 to 1
  201.     blt printInputError
  202.  
  203.     cmp r1, #50                     // Compares r1 to 9
  204.     bgt printInputError
  205.     beq fourByteCheck
  206.  
  207.     ldr r0, =userInput
  208.     ldrb r1, [r0, #3]
  209.  
  210.     cmp r1, #48
  211.     beq storeTwoNumber
  212.     bgt incrementFourByte
  213.  
  214.  
  215. fourByteCheck:
  216.     ldr r0, =userInput
  217.     ldrb r1, [r0, #1]
  218.  
  219.     cmp r1, #52
  220.     bgt printInputError
  221.  
  222.  
  223.     ldr r0, =userInput
  224.     ldrb r1, [r0, #3]
  225.  
  226.     cmp r1, #48
  227.     beq storeTwoNumber
  228.     bgt incrementFourByte
  229.  
  230.  
  231. incrementFourByte:
  232.     ldr r0, =userInput
  233.     ldrb r1, [r0, #1]
  234.  
  235.     cmp r1, #57
  236.     beq doubleIncrement
  237.  
  238.     ldr r0, =userInput           // Loading Buffer
  239.     ldrb  r10, [r0, #1]           // Loading the byte onto r1
  240.  
  241.     sub r10, r10, #47              // Subtracting 47 to convert from ASCII to int that is being incremented
  242.  
  243.     ldr r0, =userInput        // Loading the integer buffer
  244.     ldrb r4, [r0, #0]            // Storing the integer byte onto r4
  245.  
  246.     sub r4, r4, #48
  247.  
  248.     b timesTen
  249.  
  250.  
  251. doubleIncrement:
  252.     mov r4, #20
  253.  
  254.     b calcTwoDigit
  255.  
  256.  
  257. increment:
  258.     ldr r0, =userInput           // Loading Buffer
  259.     ldrb  r1, [r0, #0]           // Loading the byte onto r1
  260.     ldr r0, =rawIntBuffer        // Loading the integer buffer
  261.     sub r1, r1, #47              // Subtracting 48 to convert from ASCII to int
  262.     strb r1, [r0, #0]            // Storing the integer byte onto r1
  263.  
  264.     b calcOneDigit
  265.  
  266. incrementTwoDigit:
  267.     mov r4, #10
  268.  
  269.     b calcTwoDigit
  270.  
  271.  
  272. storeOneNumber:
  273.  
  274.   ldr r0, =userInput           // Loading Buffer
  275.   ldrb  r1, [r0, #0]           // Loading the byte onto r1
  276.   ldr r0, =rawIntBuffer        // Loading the integer buffer
  277.   sub r1, r1, #48              // Subtracting 48 to convert from ASCII to int
  278.   strb r1, [r0, #0]            // Storing the integer byte onto r1
  279.  
  280.   b calcOneDigit
  281.  
  282.  
  283. storeTwoNumber:
  284.  
  285.     ldr r0, =userInput
  286.     ldrb r4, [r0, #0]
  287.  
  288.     sub r4, r4, #48
  289.  
  290.     ldr r0, =userInput
  291.     ldrb r10, [r0, #1]
  292.  
  293.     sub r10, r10, #48
  294.  
  295.     b timesTen
  296.  
  297.  
  298. calcOneDigit:
  299.  
  300.   ldr r0, =rawIntBuffer        // Loading the int onto the r0
  301.   ldrb r4, [r0, #0]            // Loading the first byte
  302.  
  303.   cmp r4, r5                   // Comparing if my value is lower than the current min
  304.   blt setMin
  305.  
  306.   cmp r4, r6                   // Comparing if my value is higher than the current max
  307.   bgt setMax
  308.  
  309.   b continue
  310.  
  311.  
  312. calcTwoDigit:
  313.  
  314.     cmp r4, r5                   // Comparing if my value is lower than the current min
  315.     blt setMin
  316.  
  317.     cmp r4, r6                   // Comparing if my value is higher than the current max
  318.     bgt setMax
  319.  
  320.     b continue
  321.  
  322. continue:
  323.  
  324.   cmp r4, #2                  // Comparing to see if it less than or equal to two
  325.   ble twoHourParking
  326.  
  327.   cmp r4, #20                 // Comparing to see if it is more than the max parking amount
  328.   bgt maxParking
  329.  
  330.     add r7, r7, #1                          // Incrementing the counter for total number of customers
  331.   sub r12, r4, #2                 // Subtracting 2 from the total number of hours parked to calculate price
  332.  
  333.   mov r4, #0                  // Setting the incremental counter back to 0
  334.     mov r9, #0
  335.  
  336.   b calcAfterDecSet
  337.  
  338.  
  339. calcBefore:
  340.     add r4, r4, #1                          // Incrementing the counter
  341.     add r11, r11, #1                        // Adding 1 to the before the decimal value each iteration
  342.  
  343.     b calcBeforeDecSet
  344.  
  345.  
  346.  
  347. calcAfter:
  348.     add r4, r4, #1                          // Incrementing the counter
  349.     add r9, r9, #5                          // Adding 5 to r9 each iteration
  350.  
  351.     b calcAfterDecSet
  352.  
  353.  
  354.  
  355. calcAfterDecSet:
  356.     cmp r12, r4                                 // Comparing the number of hours - 2 and the counter
  357.     bgt calcAfter
  358.  
  359.     mov r4, #0                                  // Resetting the counter to 0
  360.  
  361.     cmp r9, #5                                  // Checking to see if r9 is not equal to 5
  362.     bne split
  363.  
  364.     b calcBeforeDecSet
  365.  
  366.  
  367. calcBeforeDecSet:
  368.   cmp r12, r4                                   // Comparing the number of hours - 2 and the counter
  369.     bgt calcBefore
  370.  
  371.     mov r4, #0                                  // Resetting the counter to 0
  372.  
  373.     add r11, r11, #5                            // Adding $5 for the first two hours of parking
  374.  
  375.     mov r10, #0
  376.     cmp r11, #9                                 // Comparing r11 and 9
  377.     bgt splitBeforeDigit
  378.  
  379.     b   printPrice
  380.  
  381.  
  382. setMin:
  383.   mov r5, r4                 // Setting the min register to the current min
  384.  
  385.     cmp r4, r6
  386.     bgt setMax
  387.  
  388.     b continue
  389.  
  390. setMax:
  391.   mov r6, r4                 // Setting the max register to the current max
  392.   b continue
  393.  
  394. maxParking:
  395.   add r8, r8, r1                        // Incrementing the total amount of money made
  396.   add r7, r7, #1                        // Incrementing the total number of people
  397.  
  398.     ldr r0, =dollar
  399.     mov r1, #1
  400.     bl WriteStringUART
  401.  
  402.     mov r4, #51
  403.     ldr r0, =printValue
  404.     strb r4, [r0]
  405.     ldr r0, =printValue
  406.     mov r1, #1
  407.     bl WriteStringUART
  408.  
  409.     mov r4, #51
  410.     ldr r0, =printValue
  411.     strb r4, [r0]
  412.     ldr r0, =printValue
  413.     mov r1, #1
  414.     bl WriteStringUART
  415.  
  416.     b parkingPrompt
  417.  
  418.  
  419.  
  420. twoHourParking:
  421.  
  422.   ldr r0, =rawIntBuffer
  423.   mov r1, #5
  424.  
  425.   add r8, r8, r1          // Incrementing the total amount spend counter
  426.  
  427.   add r1, r1, #48
  428.   strb r1, [r0]
  429.   mov r1, #33
  430.   strb r1, [r0, #1]
  431.  
  432.   b printOneD
  433.  
  434.  
  435. timesTen:
  436.     mov r2, #0
  437.     add r2, r4, r4
  438.     add r2, r2, r2
  439.     add r2, r2, r2
  440.     add r2, r2, r4
  441.     add r4, r2, r4
  442.     mov r2, #0
  443.  
  444.     add r4, r4, r10
  445.  
  446.  
  447.     ldr r0, =rawIntBuffer
  448.     str r4, [r0]
  449.  
  450.     b calcTwoDigit
  451.  
  452. split:
  453.  
  454.     cmp r9, #10
  455.     bge subTen
  456.  
  457.     b calcBeforeDecSet
  458.  
  459. subTen:
  460.     sub r9, r9, #10
  461.     add r11, r11, #1
  462.     b   split
  463.  
  464. splitBefore:
  465.     sub r11, r11, #10
  466.     add r10, r10, #1
  467.     b   splitBeforeDigit
  468.  
  469.  
  470. splitBeforeDigit:
  471.     cmp r11, #10
  472.     bge splitBefore
  473.  
  474.     b printPrice
  475.  
  476.  
  477.  
  478. printPrice:
  479.  
  480.     ldr r0, =dollar
  481.     mov r1, #1
  482.     bl WriteStringUART
  483.  
  484.  
  485.     add r10, r10, #48
  486.     ldr r0, =printValue
  487.     strb r10, [r0, #0]
  488.     ldr r0, =printValue
  489.     mov r1, #1
  490.     bl WriteStringUART
  491.  
  492.     add r11, r11, #48
  493.     ldr r0, =printValue
  494.     strb r11, [r0, #0]
  495.     ldr r0, =printValue
  496.     mov r1, #1
  497.     bl WriteStringUART
  498.  
  499.     ldr r0, =decimal
  500.     mov r1, #1
  501.     bl WriteStringUART
  502.  
  503.     add r9, r9, #48
  504.     ldr r0, =printValue
  505.     strb r9, [r0, #0]
  506.     ldr r0, =printValue
  507.     mov r1, #1
  508.     bl WriteStringUART
  509.  
  510.     mov r10, #0
  511.     mov r9, #0
  512.     mov r11, #0
  513.  
  514.  
  515. printOneD:
  516.  
  517.   ldr r0, =dollar
  518.   mov r1, #1
  519.   bl WriteStringUART
  520.  
  521.   ldr r0, =rawIntBuffer
  522.   mov r1, #1
  523.   bl WriteStringUART
  524.  
  525.   add r7, r7, #1
  526.   b parkingPrompt
  527.  
  528.  
  529. .section    .data
  530.  
  531. haltLoop$:
  532.     b       haltLoop$                   // End
  533.  
  534.  
  535. ExitProgram:
  536.  
  537.   ldr r0, =Terminate
  538.   mov r1, #18
  539.   bl  WriteStringUART
  540.  
  541.  
  542. // Buffers //
  543.  
  544.  
  545. rawIntBuffer:
  546.   .rept 256
  547.   .byte 0
  548.   .endr
  549.  
  550.  
  551. buffer:
  552.   .rept 256
  553.   .byte 0
  554.   .endr
  555.  
  556.  
  557.  
  558. userInput:
  559.  
  560.     .rept   256
  561.     .byte   0
  562.     .endr
  563.  
  564. printValue:
  565.     .byte 0
  566.  
  567. // Strings //
  568.  
  569. tests:
  570.   .ascii "\n\rthis is some random stuf to test" // 34
  571.  
  572.  
  573. decimal:
  574.     .ascii "."      // 1 Characters
  575.  
  576. dollar:
  577.   .ascii "$"     // 1 Characters
  578.  
  579. Terminate:
  580.   .ascii  "\n\rQuitting Program"    // 18 Characters
  581.  
  582. prompt:
  583.     .ascii  "\n\rPlease enter the number of parking hours for the customer. Press -1 for Summary or q to exit\n\r"              // 96 Characters
  584.  
  585. creator:
  586.     .ascii "\n\rCreated by: Chris Chau, Jaskaran Sidhu, Alvin Cheung"                                                       // 54 Characters
  587.  
  588. inputError:
  589.     .ascii "\n\rInvalid Number! The number should be between 1 and 24 or -1 for the summary"                                // 77 Characters
  590.  
  591. boundError:
  592.     .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