⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bbu_library.s

📁 关于PXA310的最小系统的程序,初级学习阶段会有所帮助,汇编语言编写的
💻 S
📖 第 1 页 / 共 5 页
字号:
;
;       Code branches here if there was a match on the fist byte of the input
;       string from the user AND the first byte of the BBU command. The code 
;       below checks for matches in the rest of the string.
;
;       A match is assumed when a <space> or a <NULL> on the input string
;       matches up with a <NULL> in the BBU command list.
;
15      ldrb    r6,     [r5],   #1      ; Get next byte from input buffer
        ldrb    r7,     [r3],   #1      ; Get next byte from BBU command list
        cmp     r6,     #0              ; Is this the end of the input string?
        beq     %F17                    ; Yes - check for NULL in BBU command list
        cmp     r6,     #' '            ; Is this a <space> in the input string?
        beq     %F17                    ; Yes - check for NULL in BBU command list
        cmp     r7,     #0              ; Is this byte a NULL in the BBU command list?
        beq     %B13                    ; Yes - no match - increment command count
        cmp     r6,     r7              ; Do the bytes match?
        bne     %B11                    ; No! - reset for scan of next command in list
        b       %B15                    ; Yes - try the next byte pair!
;
;       A <space> or a <NULL> was found on the user's input. If this lines up with
;       a <NULL> in the BBU command list we have a match! Otherwise the search
;       starts over again on the start of the next BBU command in the list.
;
17      cmp     r7,     #0              ; Do we have a command match?
        bne     %B11                    ; Phooey - No match - try again.
;
;       If the code gets here - we have have a command match. The value in r4
;       contains the number of matches that have FAILED so far. So to get the
;       actual command number for the match, r4 needs to be incremented by 1.
;
        add     r4,     r4,     #1      ; Update command number
;
;       Check for a NULL byte after the command name and just return to the caller
;       if there are no arguments.
;
        mov     r3,     #0              ; Set argument counter to zero
        cmp     r6,     #0              ; Anything typed in after the command?
        beq     %F99                    ; No - take the exit path
;
;       Now the fun begins as BBU searches for possible arguments that go with
;       this command. BBU enters this part of the parser when it is looking
;       for an argument to go with the command - only certain ASCII characters
;       are acceptable at this point - otherwise a syntax error is assumed.
;       The acceptable characters are:
;
;       <NULL>  = Terminates the parsing of the input string - return to caller
;       <space> = Used to seperate arguments - otherwise ignored
;       <comma> = Used to seperate arguments - otherwise ignored
;       /       = Used to indicate "a switch" on the command line.
;                 BBU will expect a single letter (A-Z) after the slash.
;                 The letter may have an optional equal sign after it with a value
;       0-9     = The start of a number entered by the user. Call the getnum
;                 subroutine to decode the next number in the input string.
;
;       Anything else = Command Syntax error
;
;
;       Register use in the following code is as follows:
;
;               r0-r2 - reserved for calls to other subroutines
;               r3 = will be used for the argument counter
;               r4 = BBU command number. (already decoded - DO NOT MODIFY)
;               r5 = points to next byte in BBU's input buffer - already set up
;
20      ldrb    r6,     [r5],   #1      ; Get next byte in command line
        cmp     r6,     #0              ; Is this a <NULL> byte?
        beq     %F98                    ; Yes - take the exit path
        cmp     r6,     #' '            ; Is the byte a <space>?
        beq     %B20                    ; Yes - get the next byte
        cmp     r6,     #','            ; Is the byte a <comma>?
        beq     %B20                    ; Yes - get the next byte
        cmp     r6,     #'/'            ; Is the byte a <foreward slash>?
        beq     %F25                    ; Yes - Process the next byte
        cmp     r6,     #'0'            ; Is the byte less than zero?
        blt     %F22                    ; Yes - Syntax error on line
        cmp     r6,     #'9'            ; Is the byte greater than 9?
        bgt     %F22                    ; Yes - Syntax error on line
;
;       Number detected - process the value
;
21      sub     r0,     r5,     #1      ; Copy input pointer to r0
        bl      BBU_getnum              ; Fetch the number
        mov     r5,     r0              ; Update the pointer
        ands    r0,     r2,     #0xF    ; Save off error bits
        beq     %F23                    ; No error - process the returned value
        cmp     r0,     #1              ; Syntax error?
        addeq   r5,     r5,     #1      ; Yes - point to byte with syntax error
        beq     %F22                    ; ...and process the error
        ldr     r0,     =BBU_PARSE_BIG  ; Otherwise - Number too big error
        bl      BBU_putstr              ; Output string        
        mov     r1,     #0              ; Set parameter count to zero
        b       %F99                    ; ... and exit
;
;                   ***** SYNTAX ERROR ENTRY POINT *****
;       Syntax Error - Insert "#" into input string where syntax error was
;       detected and send it out to the user.
;
22      sub     r5,     r5,     #1      ; Back up 1 byte
        mov     r6,     #'#'            ; Load pointer character into r6
        strb    r6,     [r5]            ; Insert this byte into the input string
        ldr     r0,     =BBU_PARSE_SYN  ; Syntax error
        bl      BBU_putstr              ; Output string
        ldr     r0,     =BBU_ibuf       ; Get input buffer
        bl      BBU_putstr              ; Output string
        bl      BBU_crlf                ; New line
        bl      BBU_crlf                ; New line
        mov     r4,     #0xC0000000     ; Don't process command & indicate syntax error
        b       %F99                    ; Exit path
;
;       Numeric value returned from input string - process the value
;
23      ldr     r7,     =BBU_CMD_ARG    ; Point to argument list
        mov     r2,     r3,     LSL #2  ; Multiply arg counter by 4 and put in r2
        add     r7,     r7,     r2      ; Point to 32-bit switch value
        str     r1,     [r7]            ; Save the argument value here
        add     r3,     r3,     #1      ; Increment argument counter
        b       %B20                    ; Continue processing input string      
;
;       Code goes here if a <FORWARD SLASH> byte was detected.
;       BBU expects a single letter after the forward slash.
;
25      ldrb    r6,     [r5],   #1      ; Get next byte in command line
        cmp     r6,     #'A'            ; Is the byte less than an "A"?
        blt     %B22                    ; Yes - generate syntax error
        cmp     r6,     #'Z'            ; The the byte greater than a Z?
        bgt     %B22                    ; Yes - generate a syntax error
;
;       So far, so good. Save this switch value in the list and continue testing
;       the input string.
;
        ldr     r7,     =BBU_CMD_SW     ; Load the switch address
        add     r7,     r7,     r3      ; Add in the argument count
        strb    r6,     [r7]            ; Save the switch value
        cmp     r6,     #'A'            ; Was the command switch an "A"?
        beq     %F40                    ; Yes - expecting an ASCII string here
;
;                       <FORWARD SLASH CODE - CONTINUED>
;       The next byte in the input string must be one of the following:
;
;       <NULL>  = Terminates the parsing of the input string - return to caller.
;       <space> = Used to seperate arguments - otherwise ignored.
;       <comma> = Used to seperate arguments - otherwise ignored.
;       /       = Indicating another switch value to be entered.
;       <equal> = Equal sign indicating a value to be entered with this switch.
;
;       Anything else = syntax error
;
        ldrb    r6,     [r5],   #1      ; Get the next byte after the switch letter (A-Z)
        cmp     r6,     #0              ; End of input string?
        addeq   r3,     r3,     #1      ; Yes - Increment argument count
        beq     %F98                    ; ...and take the exit path

        cmp     r6,     #' '            ; Is the next byte a space?
        addeq   r3,     r3,     #1      ; Yes - Increment argument count
        beq     %B20                    ; Yes - Search for next argument in command line

        cmp     r6,     #','            ; Is the next byte a comma?
        addeq   r3,     r3,     #1      ; Yes - Increment argument count
        beq     %B20                    ; Yes - Search for next argument in command line 

        cmp     r6,     #'/'            ; Is the next byte a forward slash?
        addeq   r3,     r3,     #1      ; Yes - Increment argument count
        beq     %B25                    ; Yes - get switch value 

        cmp     r6,     #'='            ; Is the next byte an equal sign?
        addeq   r5,     r5,     #1      ; Yes - adjust input byte pointer
        beq     %B21                    ; ...and get number
        b       %B22                    ; If we got here - it's a syntax error
;
;       Parser code goes here if a "/A" was detected in the input string. /A
;       is used to indicate an ASCII string is being entered on the command
;       line (only one per command line is allowed). The code below will copy
;       the ASCII string to location BBU_CMD_ASCII for later use.
;
;       This switch could have an ASCII string but to allow for a /A switch
;       with no arguments, the code will allow and "escape path" if the byte
;       following the "A" is a <NULL>, <forward slash>, <comma>, or <space>.
;       Otherwise the next byte must be an <equal sign> and is assumed to be
;       followed by text.
;
40      ldrb    r6,     [r5],   #1      ; Get the next byte
        cmp     r6,     #0              ; End of input string?
        addeq   r3,     r3,     #1      ; Yes - Increment argument count
        beq     %F98                    ; ...and take the exit path

        cmp     r6,     #'/'            ; If forward slash, assume non-ASCII
        addeq   r3,     r3,     #1      ; Yes - Increment argument count
        beq     %B25                    ; Yes - get switch value

        cmp     r6,     #','            ; Is the next byte a comma?
        addeq   r3,     r3,     #1      ; Yes - Increment argument count
        beq     %B20                    ; Yes - Search for next argument in command line 

        cmp     r6,     #' '            ; Is the next byte a space?
        addeq   r3,     r3,     #1      ; Yes - Increment argument count
        beq     %B20                    ; Yes - Search for next argument in command line 

        cmp     r6,     #'='            ; Is the next byte a <equal sign>?
        bne     %B22                    ; No - assume Syntax error
;
;       At this point we have a "/A=" condition and BBU assumes that anything
;       that follows is text until a <NULL>, <forward slash>, <space>, or
;       <comma> is encountered. Any other character is moved into the text
;       buffer for later processing by a specific command.
;
        ldr     r2,     =BBU_CMD_ASCII  ; ASCII string saved here

42      ldrb    r6,     [r5],   #1      ; Get the next byte
        cmp     r6,     #0              ; End of input string?
        addeq   r3,     r3,     #1      ; Yes - Increment argument count
        beq     %F98                    ; ...and take the exit path

        cmp     r6,     #'/'            ; If forward slash, assume non-ASCII
        addeq   r3,     r3,     #1      ; Yes - Increment argument count
        beq     %B25                    ; Yes - get switch value

        cmp     r6,     #','            ; Is the next byte a comma?
        addeq   r3,     r3,     #1      ; Yes - Increment argument count
        beq     %B20                    ; Yes - Search for next argument in command line 

        cmp     r6,     #' '            ; Is the next byte a space?
        addeq   r3,     r3,     #1      ; Yes - Increment argument count
        beq     %B20                    ; Yes - Search for next argument in command line 
;
;       If the code got here BBU assumes the character is text and places it
;       into the BBU_CMD_ASCII buffer and fetches the next input byte from
;       the command line
;
        strb    r6,     [r2],   #1      ; Save byte and increment pointer
        b       %B42                    ; Get another input byte.
;
;       Return path if command valid arguments were detected
;
98      mov     r1,     r3              ; Copy argument count to r1
        ldr     r3,     =BBU_CMD_COUNT  ; Parameter count
        str     r1,     [r3]            ; Save a copy here
;
;       Exit path if command has no arguments
;
99      ldr     r3,     =BBU_CMD_NUMB   ; Command number
        str     r4,     [r3]            ; Save a copy here
        mov     r0,     r4              ; Return command number in r0 
        ldr     r5,     =BBU_CMD_ARG    ; Point to argument list
        ldr     r2,     [r5],   #4      ; Load 1st argument into r2
        ldr     r3,     [r5]            ; Load 2nd argument into r3      
        ldmfd   sp!,    {r4-r8, pc}     ; Restore used registers, & pc
;
;       BBU command parser text messages

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -