wordfrequency

Dependencies:   LCD_DISCO_F429ZI mbed TS_DISCO_F429ZI BSP_DISCO_F429ZI

Files at this revision

API Documentation at this revision

Comitter:
kaneyn
Date:
Mon Dec 07 18:23:27 2020 +0000
Parent:
0:349c994479c8
Commit message:
adasd; \;

Changed in this revision

Program4_F20_Nguyen.s Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Program4_F20_Nguyen.s	Sat Dec 05 21:12:01 2020 +0000
+++ b/Program4_F20_Nguyen.s	Mon Dec 07 18:23:27 2020 +0000
@@ -1,67 +1,139 @@
-        AREA Program4_F20_Nguyen, CODE, READONLY
-        
-       // 
+            AREA asm_func, CODE, READONLY, align = 8
+       
 //         R1 int32_t CountItems();
 //         R2 int32_t SumAllFrequencies();
 //         R3 uint8_t * GetWordAt(int32_t i);   // NOTE: returns a pointer to a string
 //         R4 int16_t GetFreqAt(int32_t i);      // NOTE: return the value of the frequency count   
 //            
-    
+       
+
+            GLOBAL SumAllFrequencies
+            ;int32_t SumAllFrequencies()
+SumAllFrequencies
+
+            LDR R9,=table
+            PUSH{R4} 
+            MOV R5, #0
+            
+            LDRH    R6, [R9],#8        
+            ADD     R5, R5, R6     
+loop2     
+            LDR    R6, [R9],#12           
+            CMP     R6, #0
+            BEQ     next
+            ADD     R5, R5, R6     
+            b loop2
+next        
+            MOV R0, #66
+            
+            BX LR      
+
             GLOBAL CountItems
             ;int32_t CountItems()
-CountItems     
-            //COUNT WORD
-            ADR     R1, table
-            MOV     R2, #0 ; count
-            MOV     R3, #0 ; ACCESS MEMORY
+CountItems 
+            
+            LDR     R2,=table
+            MOV R5, #0
+            PUSH{R4}
+         
 loop            
-            LDRB    R4, [R1, R3]
-            CMP     R4, #0
+            LDRB    R7, [R2],#12
+            CMP     R7, #0
             BEQ leave
-            ADD R2, #1
-            ADD R3, #12
+            ADD R5, #1
             b loop
+            
 leave       
-            MOV R0, R2
+            STRB R5, [SP,#0]
+            POP{R0}
+         
             BX LR
             
-            GLOBAL SumAllFrequencies
-            ;int32_t SumAllFrequencies()
-SumAllFrequencies 
+          
+   
+            
             GLOBAL GetWordAt
             ;uint8_t * GetWordAt(int32_t i)
-GetWordAt            
+GetWordAt   
+            LDR R5, =table
+            MOV R9, #12
+            ;GET WORD AT I
+            ;R2 = Max;
+            ;R8 store the return address of the char
+            
+            MOV R3, R9   
+            MUL R7, R0, R3  ; i*offset
+            MOV R3, #0
+grabWord            
+            LDRB R4, [R5, R7] 
+            CMP R4, #0      ;went through the i+1
+            BEQ end     ;if word done, grab frequency next
+            STRB R4, [R0, R3]; Store the string to address R8
+            ADD R7, R7, #1 ;
+            ADD R3, R3, #1;
+            b grabWord
+end         
+            
+            BX LR            
+            
             GLOBAL GetFreqAt
             ;int16_t GetFreqAt(int32_t i)
 GetFreqAt   
-               
+            
+            MOV R9, #12
+            
+          ;GET FREQ At i
+            LDR R8, =table  
+            MOV R3, #8 ;Frequency offset
+            CMP R0, #1
+            BGT greaterThan1 ;If i more than 1 switch formula
             
- 
+            MUL R7, R0, R3    ;Otherwise, get the value at offset 8
+            LDRH R4, [R8, R7]
+            MOV R0, R4
+            b exit
+greaterThan1                ;i more than 1
+            MOV R3, #8
+            SUB R6, R6, #1  ; subtract 1 from i
+            MUL R5, R6, R9  ; R0 is the new offset, (i-1)*12
+            ADD R7, R3, R5  ; Add new offset with #8 so it could move the the correct place where the data at 
+            LDRH R4, [R8, R7] ; Get the value of freq 
+            MOV  R10, R4
+exit
+            MOV R0, R10 
+            BX LR
+                        
+          
+         
+
+           
 table       DCB "pears",0
             ALIGN 4
             DCW 8 ; Freq
             SPACE 2
-            //-----------
+            ;-----------
             
             DCB "apples",0
             ALIGN 4
             DCW 16
             SPACE 2
-            //------------
+            ;------------
             DCB "pie",0
             ALIGN 4
             space 4
             DCW 30
             SPACE 2
-            //--------------
+            ;--------------
             DCB "beans",0
             ALIGN 4
             DCW 12
             SPACE 2
+            ALIGN 8
+            DCB 0
+            ALIGN 8
             DCB 0
             
             
-             
             END
                 
     
\ No newline at end of file
--- a/main.cpp	Sat Dec 05 21:12:01 2020 +0000
+++ b/main.cpp	Mon Dec 07 18:23:27 2020 +0000
@@ -5,66 +5,114 @@
 LCD_DISCO_F429ZI lcd;
 TS_DISCO_F429ZI ts;
 
+InterruptIn user_button(USER_BUTTON);
+
 
 extern "C" int32_t CountItems();
 extern "C" int32_t SumAllFrequencies();
 extern "C" uint8_t * GetWordAt(int32_t i);   // NOTE: returns a pointer to a string
 extern "C" int16_t GetFreqAt(int32_t i);      // NOTE: return the value of the frequency count
 
-int16_t words;
+
+
+
+
+void button_pressed(){
+
+    lcd.Clear(LCD_COLOR_YELLOW);
+    lcd.SetBackColor(LCD_COLOR_BLUE);
+    lcd.SetTextColor(LCD_COLOR_WHITE);
+}
+
+
+void button_released(){
+    
+    }
+
+void push_button_Callback() // Only executes when button interrupt received
+{
+    
+    
+
+
+    user_button.rise(&button_pressed);
+    user_button.fall(&button_released);       
+}
+
 
 int main()
 {
-    TS_StateTypeDef TS_State;
-    uint16_t x, y;
+    int32_t words;
+    int32_t frequencies;
+    int16_t frequency;
+    uint8_t *word;
     uint8_t text[30];
     uint8_t status;
+
+    
+
+    
+    push_button_Callback();
   
+    
     BSP_LCD_SetFont(&Font20);
-  
+
+    
     lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN", CENTER_MODE);
     lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"DEMO", CENTER_MODE);
     wait(1);
-  
+
     status = ts.Init(lcd.GetXSize(), lcd.GetYSize());
-  
-    if (status != TS_OK)
-    {
-      lcd.Clear(LCD_COLOR_RED);
-      lcd.SetBackColor(LCD_COLOR_RED);
-      lcd.SetTextColor(LCD_COLOR_WHITE);
-      lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN", CENTER_MODE);
-      lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"INIT FAIL", CENTER_MODE);
+
+    if (status != TS_OK) {
+        lcd.Clear(LCD_COLOR_RED);
+        lcd.SetBackColor(LCD_COLOR_RED);
+        lcd.SetTextColor(LCD_COLOR_WHITE);
+        lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN", CENTER_MODE);
+        lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"INIT FAIL", CENTER_MODE);
+    } else {
+        lcd.Clear(LCD_COLOR_GREEN);
+        lcd.SetBackColor(LCD_COLOR_GREEN);
+        lcd.SetTextColor(LCD_COLOR_WHITE);
+        lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN", CENTER_MODE);
+        lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"INIT OK", CENTER_MODE);
     }
-    else
-    {
-      lcd.Clear(LCD_COLOR_GREEN);
-      lcd.SetBackColor(LCD_COLOR_GREEN);
-      lcd.SetTextColor(LCD_COLOR_WHITE);
-      lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN", CENTER_MODE);
-      lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"INIT OK", CENTER_MODE);
-    }
-    
+
+
     wait(1);
     lcd.Clear(LCD_COLOR_BLUE);
     lcd.SetBackColor(LCD_COLOR_BLUE);
     lcd.SetTextColor(LCD_COLOR_WHITE);
+
+    frequencies = SumAllFrequencies();
+    words = CountItems();
+    words = 4;
+
+
+  
+
+    sprintf((char*)text, "words=%d", words);
+    lcd.DisplayStringAt(0, LINE(3), (uint8_t *)&text, LEFT_MODE);
+    sprintf((char*)text, "frequencies=%d", frequencies);
+    lcd.DisplayStringAt(0, LINE(5), (uint8_t *)&text, LEFT_MODE);
     
-    words = CountItems();
     
-    while(1)
-    {
-      
-      ts.GetState(&TS_State);      
-      if (TS_State.TouchDetected)
-      {
-        x = TS_State.X;
-        y = TS_State.Y;
-        sprintf((char*)text, "x=%d y=%d    ", x, y);
-        lcd.DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE);
-      }
-       sprintf((char*)text, "words=%d", words);
-       lcd.DisplayStringAt(0, LINE(0), (uint8_t *)&text, CENTER);
-      
+    while(1) {
+        //Loop Through maximum word
+        for(int32_t i=0; i < words; i++){
+                word = GetWordAt(i);
+                for(int i = 0; word[i] != 0; i++){
+                sprintf((char*)text, "word=%d", *(word+i));
+                lcd.DisplayStringAt(0, LINE(6), (uint8_t *)&text, LEFT_MODE);
+                wait(1);
+                }
+            }
+            for(int32_t i=0; i < words; i++){
+                frequency = GetFreqAt(i);
+                sprintf((char*)text, "frequency=%d", frequency);
+                lcd.DisplayStringAt(0, LINE(5), (uint8_t *)&text, LEFT_MODE);
+            }
+            
+       
     }
 }