Advertisement
Madotsuki

ASM example

Feb 13th, 2014
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;=================================
  2. ; lab3.asm
  3. ;=================================
  4.  
  5.             #include <GENERAL.H>
  6. SEED EQU 9      ;any value between 0-9
  7.      ORG    0       ;Reset vector
  8.      GOTO   START
  9.      ORG    5       ;
  10.  
  11. START           ;your code starts here
  12. ;===================================
  13.      CLRW               ; Clears the W register (for rerunning purposes).
  14.      ADDLW      0X20    ; Adds address to W, so W=0x20.
  15.      MOVWF      FSR     ; FSR=0x20
  16.  
  17.      MOVLW      0xA     ; Set counter
  18.      MOVWF      0X40    ; Counter's address, 0XA
  19.  
  20.      CLRF       0X41    ; Clears the additive counter (for rerunning purposes).
  21.  
  22. LOOP
  23.      MOVLW      SEED    ; SEED goes to W register.
  24.      ADDWF      0X41,0  ; SEED + additive counter, result is in W
  25.      MOVWF      INDF    ; INDF is FSR, so FSR=W
  26.      INCF       FSR     ; FSR goes to next address
  27.      INCF       0X41,1  ; Increment additive counter
  28.      DECFSZ     0X40    ; Decrement counter
  29.      GOTO       LOOP    ; If counter != 0, loop
  30.  
  31.                         ; If you're here, you're done with Part 1.
  32.      CLRF       0X2A    ; Clears the total sum address, 0x2A.
  33.      CLRW               ; Clears the W register.
  34.  
  35.      ADDLW      0X20    ; Adds address to W, so W=0x20.
  36.      MOVWF      FSR     ; FSR=0x20 (If this didn't happen, FSR'd be 0x29)
  37.  
  38.      MOVLW      0XA     ; Reassign the counter to W register.
  39.      MOVWF      0X40    ; Now assign it back to 0x40
  40.  
  41.      CLRF       0X41    ; Optional, 0x41 will be unused
  42.  
  43. SUM
  44.     CLRW                ; Clears W register.
  45.     ADDWF       INDF,0  ; Current address's value goes into W register.
  46.     ADDWF       0X2A,1  ; That value gets added into 0x2A for the total sum.
  47.  
  48.     INCF        FSR     ; Move to the next address.
  49.  
  50.     DECFSZ      0X40    ; Decrement counter
  51.     GOTO        SUM     ; If counter != 0, loop
  52.  
  53. END                     ; Congratulations.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement