Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 8.57 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.  
  191.   b calcAfterDecSet
  192.  
  193.  
  194. calcBefore:
  195.     add r4, r4, #1                          // Incrementing the counter
  196.     add r11, r11, #1                            // Adding 1 to the before the decimal value each iteration
  197.  
  198.     b calcBeforeDecSet
  199.  
  200.  
  201.  
  202. calcAfter:
  203.     add r4, r4, #1                          // Incrementing the counter
  204.     add r9, r9, #5                          // Adding 5 to r9 each iteration
  205.  
  206.     b calcAfterDecSet
  207.  
  208.  
  209.  
  210. calcAfterDecSet:
  211.     cmp r12, r4                                 // Comparing the number of hours - 2 and the counter
  212.     bgt calcAfter
  213.  
  214.     mov r4, #0                                  // Resetting the counter to 0
  215.  
  216.     cmp r9, #5                                  // Checking to see if r9 is not equal to 5
  217.     bne split
  218.  
  219.     b calcBeforeDecSet
  220.  
  221.  
  222. calcBeforeDecSet:
  223.   cmp r12, r4                                   // Comparing the number of hours - 2 and the counter
  224.     bgt calcBefore
  225.  
  226.     mov r4, #0                                  // Resetting the counter to 0
  227.  
  228.     add r11, r11, #5                            // Adding $5 for the first two hours of parking
  229.  
  230.     cmp r11, #9                                 // Comparing r11 and 9
  231.     bgt splitBeforeDigit
  232.  
  233.     b   printPrice
  234.  
  235.  
  236. setMin:
  237.   mov r5, r4                 // Setting the min register to the current min
  238.  
  239.     cmp r4, r6
  240.     bgt setMax
  241.  
  242.     b continue
  243.  
  244. setMax:
  245.   mov r6, r4                 // Setting the max register to the current max
  246.   b continue
  247.  
  248. maxParking:
  249.  
  250.   ldr r0, =rawIntBuffer         // loading the int buffer
  251.   mov r1, #33                               // setting r1 to the price of the parking
  252.  
  253.   add r8, r8, r1                        // Incrementing the total amount of money made
  254.   add r7, r7, #1                        // Incrementing the total number of people
  255.  
  256.  
  257.  
  258.  
  259. twoHourParking:
  260.  
  261.   ldr r0, =rawIntBuffer
  262.   mov r1, #5
  263.  
  264.   add r8, r8, r1          // Incrementing the total amount spend counter
  265.  
  266.   add r1, r1, #48
  267.   strb r1, [r0]
  268.   mov r1, #33
  269.   strb r1, [r0, #1]
  270.  
  271.   b printOneD
  272.  
  273.  
  274. timesTen:
  275.  
  276.  
  277.  
  278.  
  279. split:
  280.     ldr r0, =buffer                         // Loading the buffer
  281.     str r9, [r0]                                // Storing r9 onto the buffer
  282.     ldrb r9, [r0, #1]                       // Loading on the second bit onto r9
  283.  
  284.     ldrb r11, [r0, #0]                      // Loading the first bit onto r11 and using this as a carryout later on
  285.  
  286.     b calcBeforeDecSet
  287.  
  288.  
  289.  
  290. splitBeforeDigit:
  291.     ldr r0, =buffer                         // Loading the buffer
  292.     str r11, [r0]                               // Storing r9 onto the buffer
  293.     ldrb r11, [r0, #1]                      // Loading on the second bit onto r11
  294.  
  295.     ldrb r10, [r0, #0]                      // Loading the first bit onto r11 and using this as a carryout later on
  296.  
  297.     // 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 /////////////////////////////////////
  298.  
  299.     b printPrice
  300.  
  301.  
  302.  
  303. printPrice:
  304.  
  305.     ldr r0, =dollar
  306.     mov r1, #1
  307.     bl WriteStringUART
  308.  
  309.  
  310.     add r10, r10, #48
  311.     ldr r0, =printValue
  312.     strb r10, [r0]
  313.     ldr r0, =printValue
  314.     mov r1, #1
  315.     bl WriteStringUART
  316.  
  317.     add r11, r11, #48
  318.     ldr r0, =printValue
  319.     strb r11, [r0]
  320.     ldr r0, =printValue
  321.     mov r1, #1
  322.     bl WriteStringUART
  323.  
  324.     ldr r0, =decimal
  325.     mov r1, #1
  326.     bl WriteStringUART
  327.  
  328.     add r9, r9, #48
  329.     ldr r0, =printValue
  330.     strb r9, [r0]
  331.     ldr r0, =printValue
  332.     mov r1, #1
  333.     bl WriteStringUART
  334.  
  335.     mov r10, #0
  336.     mov r9, #0
  337.     mov r11, #0
  338.  
  339.  
  340. printOneD:
  341.  
  342.   ldr r0, =dollar
  343.   mov r1, #1
  344.   bl WriteStringUART
  345.  
  346.   ldr r0, =rawIntBuffer
  347.   mov r1, #1
  348.   bl WriteStringUART
  349.  
  350.   add r7, r7, #1
  351.   b parkingPrompt
  352.  
  353.  
  354. .section    .data
  355.  
  356. haltLoop$:
  357.     b       haltLoop$                   // End
  358.  
  359.  
  360. ExitProgram:
  361.  
  362.   ldr r0, =Terminate
  363.   mov r1, #18
  364.   bl  WriteStringUART
  365.  
  366.  
  367. // Buffers //
  368.  
  369.  
  370. rawIntBuffer:
  371.   .rept 256
  372.   .byte 0
  373.   .endr
  374.  
  375.  
  376. buffer:
  377.   .rept 256
  378.   .byte 0
  379.   .endr
  380.  
  381.  
  382.  
  383. userInput:
  384.  
  385.     .rept   256
  386.     .byte   0
  387.     .endr
  388.  
  389. printValue:
  390.     .byte 0
  391.  
  392. // Strings //
  393.  
  394. tests:
  395.   .ascii "\n\rthis is some random shit to test" // 34
  396.  
  397.  
  398. decimal:
  399.     .ascii "."      // 1 Characters
  400.  
  401. dollar:
  402.   .ascii "$"     // 1 Characters
  403.  
  404. Terminate:
  405.   .ascii  "\n\rQuitting Program"    // 18 Characters
  406.  
  407. prompt:
  408.     .ascii  "\n\rPlease enter the number of parking hours for the customer. Press -1 for Summary or q to exit\n\r"              // 96 Characters
  409.  
  410. creator:
  411.     .ascii "\n\rCreated by: Chris Chau, Jaskaran Sidhu, Alvin Cheung"                                                       // 54 Characters
  412.  
  413. inputError:
  414.     .ascii "\n\rInvalid Number! The number should be between 1 and 24 or -1 for the summary"                                // 77 Characters
  415.  
  416. boundError:
  417.     .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