
This is program 4
Dependencies: LCD_DISCO_F429ZI mbed TS_DISCO_F429ZI BSP_DISCO_F429ZI
Diff: PROGRAM4_F20_Harrison.s
- Revision:
- 2:a38c09fad0fe
- Parent:
- 1:2308340de21d
- Child:
- 3:2ec663c724ea
--- a/PROGRAM4_F20_Harrison.s Sun Dec 06 05:36:32 2020 +0000 +++ b/PROGRAM4_F20_Harrison.s Mon Dec 07 04:03:14 2020 +0000 @@ -2,7 +2,7 @@ GLOBAL CountItems ;int32_t CountItems() - + CountItems ; get max num of words MOV R4, #0 ; track num of words ADR R1, table ; get address of beginning of table @@ -14,7 +14,6 @@ CMP R2, #0 ; compare value in table to 0 BEQ leave1 ADD R4, R4, #1 ; add 1 to num of words - ;LDRH does not work LDR R2, [R1, R3] ; move R3 num of bytes in the table ADD R3, R3, #12 ; add 12 bytes to R3 B getWordCount ; loop back @@ -39,7 +38,7 @@ BEQ leave ; break because looped through entire table ADD R4, R4, R2 ; add current frequency to total frequency LDR R2, [R1, R3] ; move R3 num of bytes in the table - ADD R3, R3, #12 ; add 24 bytes to R3 + ADD R3, R3, #12 ; add 12 bytes to R3 B getFrequencyCount ; loop back leave @@ -53,15 +52,16 @@ MOV R1, #1 ADR R2, table ; get address of beginning of table LDR R3, [R2] ; get value at address of beginning of table - MOV R4, #24 ; use to move to next word in table + MOV R4, #12 ; use to move to next word in table B findWord findWord CMP R1, R0 ; compare 1 to i BEQ wordFound ; break because word found LDR R3, [R2, R4] ; move R4 num of bytes in table - ADD R4, R4, #24 ; add 24 bytes to R3 - B wordFound + ADD R4, R4, #12 ; add 12 bytes to R3 + ADD R1, R1, #1 + B findWord wordFound MOV R0, R3 @@ -74,38 +74,38 @@ MOV R1, #1 ADR R2, table ; get address of beginning of table MOV R3, #8 ; use 8 to account for word being first in table - LDR R4, [R2, R3] ; get value where first frequency is stored in table + LDRH R4, [R2, R3] ; get value where first frequency is stored in table ADD R3, R3, #12 ; use to move to next frequency in table B findFrequency findFrequency - CMP R1, R0 ; compare 1 to i + CMP R1, R0 ; compare R1 to i BEQ frequencyFound ; break because frequency found - LDR R4, [R2, R3] ; move R3 num of bytes in table - ADD R4, R4, #12 ; add 12 bytes to R3 + LDRH R4, [R2, R3] ; move R3 num of bytes in table + ADD R3, R3, #12 ; add 12 bytes to R3 + ADD R1, R1, #1 B findFrequency frequencyFound - MOV R0, R3 + MOV R0, R4 BX LR stop B stop -table DCB "pears",0 - SPACE 2 - DCW 8 - SPACE 2 - DCB "apples",0 - SPACE 1 - DCW 16 +table DCB "pie",0 + SPACE 4 + DCW 34 SPACE 2 - DCB "pie",0 - SPACE 4 - DCW 30 + DCB "cake",0 + SPACE 3 + DCW 29 SPACE 2 - DCB "beans",0 + DCB "souffle",0 + DCW 22 SPACE 2 - DCW 12 + DCB "cookie",0 + SPACE 1 + DCW 15 SPACE 2 DCB 0