Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
05/12/03 14:43
Read: times


 
#45290 - Indirect addressing, loops and subroutin
Hi, I'm sorry. I posed this already but without a proper subject. I have contacted the moderators to remove the other one.

I am trying to learn how to use Indirect addressing and loops and subroutines.

As far as I can see the code below should work fine.

It takes 3 numbers and finds the lowest.

Can yopu see what I'm doing wrong. The first calc, 1-9 works and stores 1 in the var 'smallest'.

But the when it tries to do 9-8 it keeps coming up with an answer of zero. I'm really pulling my hair out - cos I know this is supposed to be simple.

I have to use these techniques.
------------------------------------------

X equ 70h ; store X at mem loc 70h
Y equ 71h ; store Y at mem loc 71h
Z equ 72h ; store Z at mem loc 72h
smallest equ 73h ; store smallest at mem loc 73h

org 100h

mov R0, #70h ; point the contents of 70h to R0
mov R1, #71h ; point the contents of 71h to R1
mov R2, #02 ; set the value of R2 to be 2

mov X, #01
mov Y, #09
mov Z, #08

loop:
acall find_smallest
inc R0
inc R1
djnz R2, loop ; if(R2!=0) goto loop
sjmp finish ; goto finish

find_smallest:
mov a, @R0 ; move what is in mem loc ass with R0 to the acc
subb a, @R1 ; subtract and carry what is in mem loc ass with R1 from a and carry
jc RO_is_smallest ; if R1>R0 (carry flag set) go to 'RO_is_smallest'
mov smallest, @R1 ; move what is in the acc to 'smallest'
ret

RO_is_smallest:
mov smallest, @R0 ; move what is in the acc to
ret

finish:


end


Thank you so much if you can point me back on track.

M@)

List of 4 messages in thread
TopicAuthorDate
Indirect addressing, loops and subroutin            01/01/70 00:00      
   RE: Indirect addressing, loops and subroutin            01/01/70 00:00      
      RE: Indirect addressing, loops and subroutin            01/01/70 00:00      
   RE: Indirect addressing, loops and subroutin            01/01/70 00:00      

Back to Subject List