For example I have a file (codes.txt) with these code nums
CODE1 fcc "3392236"
CODE2 fcc "1234550"
CODE3 fcc "7654361"
CODE4 fcc "1212223"
CODE5 fcc "1233211"
CODE6 fcc "1232343"
Next, a subroutine called readCode_Driver which job is to help reading these numbers with another subroutine called toInteger.asm. The readCode_Driver.asm file goes as follow:
NUMBEROFCODES equ 6 ; Six CODEs to process
LENGTHOFCODE equ 7 ; Each code is 7 digits
PROGRAMSTART equ $2000 ; Executable code as in (programming code) starts here
STORAGE1 equ $1000 ; Storage starts here for original code numbers
org STORAGE1
CODES
#include codes.txt
org ProgramStart
lds #ProgramStart
; Setup to use toInterger
ldx #CODES ; point to first digit of NUM1 ex: 3
ldab #LENGTHOFCODE ; code's length
clra ; loop counter
ConvertCODEs
psha
pshb
jsr toInteger ; Convert from ASCII to Integer
pulb ; Retrieve CODE's Length (called a POP)
pula ; Retrieve Loop Counter
inca ; Setup to loop again
cmpa #NUMBEROFCODES ; All six codes converted?
bne ConvertCODEs ; No, so continue on looping
swi ; All six CODEs converted?
#include toInteger.asm ; subroutine to test with this driver
end
This is my toInteger.asm file and its content:
toInteger ldaa 0,x ; get ASCII value
suba #$30 ; convert to an integer
staa 0,x ; store integer
inx ; point to next value
decb ; one less value to do
cmpb #0 ; Is this the last ASCII value?
bne toInteger ; No, more to do
rts ; Yes, so we're done
to validate these code, I need another subroutine called addeven.asm. This subroutine is suppose to add even numbers in the codes. For example, CODE1 has 3392236. The even numbers are chosen from this position 0 1 2 3 4 5 6. In CODE1, even numbers would be 3(pos 0),9(pos 2),2(pos 4), and 6(pos 6). Odds numbers would be 3(post1),2(pos3),3(pos5)
Question is, how do i take the even numbers in code1, multiply each individual even numbers by 2, and then add them in assembly language. It goes like this 2*3,2*9,2*2,2*6 then add them like this 6+1+8+4+1+2. For these code 18 is 1 and 8 so I added them like 1+8. The micro controller is the dragon 12 68hc12
Somehow 68xx series comes to mind...
The multiplication by 2 can be done easily by shifting, and skipping every second byte can be done the same way you did the conversion, except INCing the x twice. With odd bytes, you INC x before the call.