Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;=================================
- ; lab3.asm
- ;=================================
- #include <GENERAL.H>
- SEED EQU 9 ;any value between 0-9
- ORG 0 ;Reset vector
- GOTO START
- ORG 5 ;
- START ;your code starts here
- ;===================================
- CLRW ; Clears the W register (for rerunning purposes).
- ADDLW 0X20 ; Adds address to W, so W=0x20.
- MOVWF FSR ; FSR=0x20
- MOVLW 0xA ; Set counter
- MOVWF 0X40 ; Counter's address, 0XA
- CLRF 0X41 ; Clears the additive counter (for rerunning purposes).
- LOOP
- MOVLW SEED ; SEED goes to W register.
- ADDWF 0X41,0 ; SEED + additive counter, result is in W
- MOVWF INDF ; INDF is FSR, so FSR=W
- INCF FSR ; FSR goes to next address
- INCF 0X41,1 ; Increment additive counter
- DECFSZ 0X40 ; Decrement counter
- GOTO LOOP ; If counter != 0, loop
- ; If you're here, you're done with Part 1.
- CLRF 0X2A ; Clears the total sum address, 0x2A.
- CLRW ; Clears the W register.
- ADDLW 0X20 ; Adds address to W, so W=0x20.
- MOVWF FSR ; FSR=0x20 (If this didn't happen, FSR'd be 0x29)
- MOVLW 0XA ; Reassign the counter to W register.
- MOVWF 0X40 ; Now assign it back to 0x40
- CLRF 0X41 ; Optional, 0x41 will be unused
- SUM
- CLRW ; Clears W register.
- ADDWF INDF,0 ; Current address's value goes into W register.
- ADDWF 0X2A,1 ; That value gets added into 0x2A for the total sum.
- INCF FSR ; Move to the next address.
- DECFSZ 0X40 ; Decrement counter
- GOTO SUM ; If counter != 0, loop
- END ; Congratulations.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement