Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 8.59 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.     ldr     r0, =creator                    // Chris, Jas, Alvin
  17.     mov     r1, #54                           // Allocates bytes
  18.     bl      WriteStringUART               // Call print
  19.  
  20.  
  21.  
  22.  
  23.  
  24. test:
  25.   ldr r0, =tests
  26.   mov r1, #34
  27.   bl WriteStringUART
  28.  
  29.   b parkingPrompt
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37. parkingPrompt:
  38.  
  39.     ldr     r0, =prompt                    // Asks user for hours
  40.     mov     r1, #96                          // Allocates bytes
  41.     bl      WriteStringUART              // Call Print
  42.  
  43.     ldr     r0, =userInput             // Buffer for user input
  44.     mov     r1, #256
  45.     bl      ReadLineUART                   // Input in r0
  46.  
  47.  
  48.     // Compare bits //
  49.  
  50.     cmp     r0, #1                           // Checks if user input == 1 byte
  51.     blt     printInputError              // Input < 1
  52.     beq     firstDigit                     // Go to first digit
  53.  
  54.     cmp     r0, #2                           // Checks if user input == 2 bytes
  55.     beq     secondDigit                    // Go to second digit
  56.  
  57.     cmp     r0, #3                         // Checks if user input == 3 bytes
  58.     beq     thirdDigit                     // Go to third digit
  59.  
  60.     cmp     r0, #4                           // Checks if user input == 4 bytes
  61.     beq     fourthDigit                    // Go to fourth digit
  62.  
  63.     cmp     r0, #5                           // Checks if user input == 5 bytes
  64.     bge     printBoundError              // Out of bound error
  65.  
  66.  
  67.  
  68. printInputError:
  69.  
  70.     ldr     r0, =inputError              // Error message for invalid characters
  71.     mov     r1, #77                          // Allocates bytes
  72.     bl      WriteStringUART              // Prints
  73.  
  74.   b parkingPrompt
  75.  
  76.  
  77.  
  78. printBoundError:
  79.  
  80.     ldr     r0, =boundError              // Error message for out of bound integers
  81.     mov     r1, #51                          // Allocates bytes
  82.     bl      WriteStringUART              // Prints
  83.  
  84.   b parkingPrompt
  85.  
  86.  
  87.  
  88. firstDigit:
  89.  
  90.   ldr r0, =userInput           // Address of Buffer
  91.   ldrb r1, [r0, #0]            // Loading the first character
  92.  
  93.   cmp r1, #81                  // Compares the one digit to ASCII value for q
  94.   beq ExitProgram
  95.  
  96.   cmp r1, #113                 // Compares the one digit to ASCII value for Q
  97.   beq ExitProgram
  98.  
  99.   cmp r1, #49                  // Compares r1 to 1
  100.   blt printInputError
  101.  
  102.   cmp r1, #57                  // Compares r1 to 9
  103.   bgt printInputError
  104.  
  105.   b storeOneNumber
  106.  
  107.  
  108.  
  109. secondDigit:
  110.  
  111.     ldr r0, =userInput                  // Address of Buffer
  112.     ldrb r1, [r0, #0]                       // Loading the first character onto r1
  113.  
  114.     cmp r1, #50                                 // Checking if the first character is greater than 2
  115.     bgt printInputError                 // Branch to error if it is greater than 2
  116.  
  117.     cmp r1, #48                                 // Compare to see if the input is a number and not other characters
  118.     blt printInputError
  119.  
  120.     ldr r0, =userInput                  // Address of the buffer
  121.     ldrb r1, [r0, #1]                       // Loading the second character onto r1
  122.  
  123.     cmp r1, #57                                 // Comparing to see if the second digit is a ascii character greater than 9
  124.     bgt printInputError                 // Branch to an error message because this shows the byte was a non-number character
  125.  
  126.     cmp r1, #48                                 // Comparing to see if the second digit is a ascii character less than 0
  127.     blt printInputError                 // Branch to error message
  128.  
  129.     b storeTwoNumber
  130.  
  131.  
  132. thirdDigit:
  133.     b test
  134. fourthDigit:
  135.     b test
  136.  
  137.  
  138. storeOneNumber:
  139.  
  140.   ldr r0, =userInput           // Loading Buffer
  141.   ldrb  r1, [r0, #0]           // Loading the byte onto r1
  142.   ldr r0, =rawIntBuffer        // Loading the integer buffer
  143.   sub r1, r1, #48              // Subtracting 48 to convert from ASCII to int
  144.   strb r1, [r0, #0]            // Storing the integer byte onto r1
  145.  
  146.   b calcOneDigit
  147.  
  148.  
  149. storeTwoNumber:
  150.  
  151.     ldr r0, =userInput
  152.     ldrb r4, [r0, #0]
  153.  
  154.     sub r4, r4, #48
  155.  
  156.     ldr r0, =userInput
  157.     ldrb r10, [r0, #1]
  158.  
  159.     sub r10, r10, #48
  160.  
  161.     bl timesTen
  162.  
  163.  
  164. calcOneDigit:
  165.  
  166.   ldr r0, =rawIntBuffer        // Loading the int onto the r0
  167.   ldrb r4, [r0, #0]            // Loading the first byte
  168.  
  169.   cmp r4, r5                   // Comparing if my value is lower than the current min
  170.   blt setMin
  171.  
  172.   cmp r4, r6                   // Comparing if my value is higher than the current max
  173.   bgt setMax
  174.  
  175.   b continue
  176.  
  177.  
  178. continue:
  179.  
  180.   cmp r4, #2                  // Comparing to see if it less than or equal to two
  181.   ble twoHourParking
  182.  
  183.   cmp r4, #20                 // Comparing to see if it is more than the max parking amount
  184.   bgt maxParking
  185.  
  186.     add r7, r7, #1                          // Incrementing the counter for total number of customers
  187.   sub r12, r4, #2                 // Subtracting 2 from the total number of hours parked to calculate price
  188.  
  189.   mov r4, #0                  // Setting the incremental counter back to 0
  190.     mov r9, #0
  191.  
  192.   b calcAfterDecSet
  193.  
  194.  
  195. calcBefore:
  196.     add r4, r4, #1                          // Incrementing the counter
  197.     add r11, r11, #1                        // Adding 1 to the before the decimal value each iteration
  198.  
  199.     b calcBeforeDecSet
  200.  
  201.  
  202.  
  203. calcAfter:
  204.     add r4, r4, #1                          // Incrementing the counter
  205.     add r9, r9, #5                          // Adding 5 to r9 each iteration
  206.  
  207.     b calcAfterDecSet
  208.  
  209.  
  210.  
  211. calcAfterDecSet:
  212.     cmp r12, r4                                 // Comparing the number of hours - 2 and the counter
  213.     bgt calcAfter
  214.  
  215.     mov r4, #0                                  // Resetting the counter to 0
  216.  
  217.     cmp r9, #5                                  // Checking to see if r9 is not equal to 5
  218.     bne split
  219.  
  220.     b calcBeforeDecSet
  221.  
  222.  
  223. calcBeforeDecSet:
  224.   cmp r12, r4                                   // Comparing the number of hours - 2 and the counter
  225.     bgt calcBefore
  226.  
  227.     mov r4, #0                                  // Resetting the counter to 0
  228.  
  229.     add r11, r11, #5                            // Adding $5 for the first two hours of parking
  230.  
  231.     cmp r11, #9                                 // Comparing r11 and 9
  232.     bgt splitBeforeDigit
  233.  
  234.     b   printPrice
  235.  
  236.  
  237. setMin:
  238.   mov r5, r4                 // Setting the min register to the current min
  239.  
  240.     cmp r4, r6
  241.     bgt setMax
  242.  
  243.     b continue
  244.  
  245. setMax:
  246.   mov r6, r4                 // Setting the max register to the current max
  247.   b continue
  248.  
  249. maxParking:
  250.  
  251.   ldr r0, =rawIntBuffer         // loading the int buffer
  252.   mov r1, #33                               // setting r1 to the price of the parking
  253.  
  254.   add r8, r8, r1                        // Incrementing the total amount of money made
  255.   add r7, r7, #1                        // Incrementing the total number of people
  256.  
  257.  
  258.  
  259.  
  260. twoHourParking:
  261.  
  262.   ldr r0, =rawIntBuffer
  263.   mov r1, #5
  264.  
  265.   add r8, r8, r1          // Incrementing the total amount spend counter
  266.  
  267.   add r1, r1, #48
  268.   strb r1, [r0]
  269.   mov r1, #33
  270.   strb r1, [r0, #1]
  271.  
  272.   b printOneD
  273.  
  274.  
  275. timesTen:
  276.  
  277.  
  278.  
  279.  
  280. split:
  281.     ldr r0, =buffer             // Loading the buffer
  282.     str r9, [r0]                                // Storing r9 onto the buffer
  283.     ldrb r9, [r0, #1]                       // Loading on the second bit onto r9
  284.  
  285.     ldrb r11, [r0, #0]                      // Loading the first bit onto r11 and using this as a carryout later on
  286.  
  287.     b calcBeforeDecSet
  288.  
  289.  
  290.  
  291. splitBeforeDigit:
  292.     ldr r0, =buffer                         // Loading the buffer
  293.     str r11, [r0]                               // Storing r9 onto the buffer
  294.     ldrb r11, [r0, #1]                      // Loading on the second bit onto r11
  295.  
  296.     ldrb r10, [r0, #0]                      // Loading the first bit onto r11 and using this as a carryout later on
  297.  
  298.     // 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 /////////////////////////////////////
  299.  
  300.     b printPrice
  301.  
  302.  
  303.  
  304. printPrice:
  305.  
  306.     ldr r0, =dollar
  307.     mov r1, #1
  308.     bl WriteStringUART
  309.  
  310.  
  311.     add r10, r10, #48
  312.     ldr r0, =printValue
  313.     strb r10, [r0, #0]
  314.     ldr r0, =printValue
  315.     mov r1, #1
  316.     bl WriteStringUART
  317.  
  318.     add r11, r11, #48
  319.     ldr r0, =printValue
  320.     strb r11, [r0, #0]
  321.     ldr r0, =printValue
  322.     mov r1, #1
  323.     bl WriteStringUART
  324.  
  325.     ldr r0, =decimal
  326.     mov r1, #1
  327.     bl WriteStringUART
  328.  
  329.     add r9, r9, #48
  330.     ldr r0, =printValue
  331.     strb r9, [r0, #0]
  332.     ldr r0, =printValue
  333.     mov r1, #1
  334.     bl WriteStringUART
  335.  
  336.     mov r10, #0
  337.     mov r9, #0
  338.     mov r11, #0
  339.  
  340.  
  341. printOneD:
  342.  
  343.   ldr r0, =dollar
  344.   mov r1, #1
  345.   bl WriteStringUART
  346.  
  347.   ldr r0, =rawIntBuffer
  348.   mov r1, #1
  349.   bl WriteStringUART
  350.  
  351.   add r7, r7, #1
  352.   b parkingPrompt
  353.  
  354.  
  355. .section    .data
  356.  
  357. haltLoop$:
  358.     b       haltLoop$                   // End
  359.  
  360.  
  361. ExitProgram:
  362.  
  363.   ldr r0, =Terminate
  364.   mov r1, #18
  365.   bl  WriteStringUART
  366.  
  367.  
  368. // Buffers //
  369.  
  370.  
  371. rawIntBuffer:
  372.   .rept 256
  373.   .byte 0
  374.   .endr
  375.  
  376.  
  377. buffer:
  378.   .rept 256
  379.   .byte 0
  380.   .endr
  381.  
  382.  
  383.  
  384. userInput:
  385.  
  386.     .rept   256
  387.     .byte   0
  388.     .endr
  389.  
  390. printValue:
  391.     .byte 0
  392.  
  393. // Strings //
  394.  
  395. tests:
  396.   .ascii "\n\rthis is some random stuf to test" // 34
  397.  
  398.  
  399. decimal:
  400.     .ascii "."      // 1 Characters
  401.  
  402. dollar:
  403.   .ascii "$"     // 1 Characters
  404.  
  405. Terminate:
  406.   .ascii  "\n\rQuitting Program"    // 18 Characters
  407.  
  408. prompt:
  409.     .ascii  "\n\rPlease enter the number of parking hours for the customer. Press -1 for Summary or q to exit\n\r"              // 96 Characters
  410.  
  411. creator:
  412.     .ascii "\n\rCreated by: Chris Chau, Jaskaran Sidhu, Alvin Cheung"                                                       // 54 Characters
  413.  
  414. inputError:
  415.     .ascii "\n\rInvalid Number! The number should be between 1 and 24 or -1 for the summary"                                // 77 Characters
  416.  
  417. boundError:
  418.     .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