TDB9936
Newbie level 1
Well currently ive been working on this for about 3 days and still having a problem. Ive narrowed it down to a variable not decrementing correctly.. Ive exhausted all options. Im new to assembly and probably missing something easy so heres my program with disassembly showing the macro
what it needs to do is us an add macro to add two variables together using a loop. simple yet im missing something.
---------- Post added at 22:45 ---------- Previous post was at 21:15 ----------
solved my own problem with a lil hard work
for anyone else that wants to know or runs into the problem heres what I changed in my macro.
what it needs to do is us an add macro to add two variables together using a loop. simple yet im missing something.
Code:
list p=18f4520
#include p18f4520.inc
ADDLNG macro sum, num1, num2, lgth
local IDX = lgth
local loop
movf num1+IDX, w;load w register with a literal
;value assigned to the label
;'num1'.
addwf num2+IDX, w ;load w register with a literal
;value assigned to the label
;'num2'.
movwf sum+IDX ;load w register to an addresss
;location assigned to the label
;'sum'.
IDX-=.1
loop movf num1+IDX, w
addwfc num2+IDX, w
movwf sum+IDX
decfsz IDX, F
goto loop
endm
cblock
VAR1: 0x10 ;creates a variable called VAR1 at 0 and places VAR2 0x40 bytes after VAR1
VAR2: 0x10
SUM: 0x10
length
endc
PROG CODE ; Set the start of code from linker script
main
clrf PORTA ;Initialize PORTA by clearing output data latches
clrf LATA ;Alternate method to clear output data latches
movlw 0FH
movwf ADCON1
movlw 07h
movwf CMCON
movlw 0
movwf TRISA
bsf TRISA, 0
movlw 0x10 ;VAR1 is now set to 103875ABEDF0398DC9ABEDF0398DC9
movwf VAR1
movlw 0x38
movwf VAR1+.1
movlw 0x75
movwf VAR1+.2
movlw 0xAB
movwf VAR1+.3
movlw 0xED
movwf VAR1+.4
movlw 0xF0
movwf VAR1+.5
movlw 0x39
movwf VAR1+.6
movlw 0x8D
movwf VAR1+.7
movlw 0xC9
movwf VAR1+.8
movlw 0xAB
movwf VAR1+.9
movlw 0xED
movwf VAR1+.10
movlw 0xF0
movwf VAR1+.11
movlw 0x39
movwf VAR1+.12
movlw 0x8D
movwf VAR1+.13
movlw 0xC9
movwf VAR1+.14
movlw 0x9A ;VAR2 is now set to 9ABEDF0398DC9ABEDF0398DCABEDF
movwf VAR2
movlw 0xBE
movwf VAR2+.1
movlw 0xDF
movwf VAR2+.2
movlw 0x03
movwf VAR2+.3
movlw 0x98
movwf VAR2+.4
movlw 0xDC
movwf VAR2+.5
movlw 0x9A
movwf VAR2+.6
movlw 0xBE
movwf VAR2+.7
movlw 0xDF
movwf VAR2+.8
movlw 0x03
movwf VAR2+.9
movlw 0x98
movwf VAR2+.10
movlw 0xDC
movwf VAR2+.11
movlw 0xAB
movwf VAR2+.12
movlw 0xED
movwf VAR2+.13
movlw 0x0F
movwf VAR2+.14
btg PORTA, 1
movf VAR1, 0
NOP
NOP
NOP
ADDLNG SUM, VAR1, VAR2, .14
NOP
NOP
end
Code:
0096 500E MOVF 0xe, W, ACCESS 118: ADDLNG SUM, VAR1, VAR2, .14
0098 241E ADDWF 0x1e, W, ACCESS
009A 6E2E MOVWF 0x2e, ACCESS
009C 500D MOVF 0xd, W, ACCESS
009E 201D ADDWFC 0x1d, W, ACCESS
00A0 6E2D MOVWF 0x2d, ACCESS
00A2 2E0D DECFSZ 0xd, F, ACCESS
00A4 EF4E GOTO 0x9c
00A6 F000 NOP
00A8 0000 NOP 119: NOP
---------- Post added at 22:45 ---------- Previous post was at 21:15 ----------
solved my own problem with a lil hard work
for anyone else that wants to know or runs into the problem heres what I changed in my macro.
Code:
ADDLNG macro sum, num1, num2, lgth
variable i
i = lgth
local loop
movf num1+i, 0;load w register with a literal
;value assigned to the label
;'num1'.
addwf num2+i, 0 ;load w register with a literal
;value assigned to the label
;'num2'.
movwf sum+i ;load w register to an addresss
;location assigned to the label
;'sum'.
i -=1
while 0<=i ;loop until i = 0 at which we are done.
movf num1+i, 0
addwfc num2+i, 0
movwf sum+i ;output to sum
i -= 1
endw
endm