Code in question:
; Copy all the values which are divisible by four to a starting address $1600.
; The indivisible by four is pushed onto the stack, and use the effective address
; to pull them out after finishing the loop. The starting address is $1650.
; Array pointer starts from the beginning, and using DBNE to decrement the loop
N equ 12
org $1600
fill 0,128 ; each row in the memory displays 16 bytes
cnt rmb 1 ; indivisible counter
org $1ff0
fill 0,16
org $2000 ; start RAM address
lds #$2000 ; initialize the stack pointer
ldy #$1600 ; load the starting address for divisible by 4
ldx #array ; load the starting address of array to Reg. X
ldaa #N ; use B as the loop counter, B = N
clr cnt ; clear cnt counter
loop brclr 0,x,$03,yes ; if bits 1 & 0 are 0s, then branch to yes
ldab 1,x+
inc cnt ; increment cnt counter for indivisible
pshb ; push onto the stack for the indivisible
bra chkend
yes movb 1,x+,1,y+ ; copy the divisible by 4 value to a new location
chkend dbne a,loop ; decrement B by 1, if B NE 0, branch to loop
; use the effective address to load/pull the elements from the stack
ldy #$1650
ldx #$1fff ; first available address for the stack
ldaa cnt
loop2 movb 1,x-,1,y+ ; stack is first in last out
dbne a,loop2
swi
array db 3,4,9,12,19,20,24,31,48,53,64,72
end
I'm taking mircoprocessors and my professor gave us this code to change, but I'm unsure on how to. This is the first time we're "programming" in Assembly.
He also came us this to help:
EEEN 3449
Lab 4c:
• idiv => Accumulator D / Register X, the remainder refreshes to D
• Register X has the constant 3.
• Register Y is utilized as the array pointer.
• Although there is nothing stored in Accumulator A, A:B => D
• You can use Accumulator B as the loop counter, and store the
starting address for divisible by 3.
• In the beginning of the loop, you have to store loop counter value in
another temporary address, like $15FE.
• clr A, and ldab 0,y will generate [D] = [0 : 1st array element]
• Carry out the idiv and compare Accumulator D with 0.
• If Accumulator D is non-zero, push the accumulator B onto the stack.
• If Accumulator D is zero, reload the updated address for divisible by 3.
• After sorting out the array element where to store them, reload the
loop counter from $15FE, and increment the array pointer.
• Then use dbne b,loop to execute the next iteration.
Thanks to not knowing Assembly, I don't know how to use this to change the code correctly.
The code shown is pulling numbers that are divisble by 4 and putting them into the memory at $1600, I think. I need to change this code and make it pull numbers that are divisble by 3. No clue where to start and begin testing since I don't know a whole lot on Assembly.
Any help would be great as well as if you could help me understand what's happening. I do want to learn, but I can't seem to find much on Assembly.
I've tried testing things myself, but I keep getting errors and don't know where they are or how to fix them.