include radix dec sumhi set 0x01 sumlo set 0x00 lpcnt set 0x

#include <p18F8722.inc>

                             radix     dec

sum_hi               set         0x01

sum_lo               set         0x00

lp_cnt                  set         0x02                   

kk                         equ       D\'50\'

                             org        0x00

                             goto      start

                             org        0x08

                             retfie

                             org        0x18

                             retfie

start                    movlw kk

                             movwf lp_cnt

                             clrf         sum_hi,A

                             clrf         sum_lo,A

                             movlw upper(array)

                             movwf TBLPTRU,A

                             movlw high(array)

                             movwf TBLPTRH,A

                             movlw low(array)

                             movwf TBLPTRL,A

loop                     tblrd*+

                             btfsc      TABLAT,0,A

                             goto      next

                             movf     TABLAT,W,A

                             addwf   sum_lo,F,A

                             clrf         WREG,A

                             addwfc sum_hi,F,A

next                     decfsz   lp_cnt,F,A

                             goto      loop

                             nop

array                   db          01,02,03,04,05,06,07,08,09,10

                             db          11,12,13,14,15,16,17,18,19,20

                             db          21,22,23,24,25,26,27,28,29,30

                             db          31,32,33,34,35,36,37,38,39,40

                             db          41,42,43,44,45,46,47,48,49,50

              end

Write or alter the code above to determine the smallest unsigned byte in the array below, and put the result in 0x50 of the Access file register.

array db 14,09,59,52,15,36,07,48,29,11

db 15,22,13,94,45,16,47,28,49,23

db 44,52,83,74,25,26,29,78,39,60

db 31,42,33,34,04,36,37,38,39,41

db 51,42,13,54,45,26,37,42,19,40

Solution

#include <p18F8722.inc>

                             radix     dec

sum_hi               set         0x01

sum_lo               set         0x00

lp_cnt                  set         0x02                 

kk                         equ       D\'50\'

                             org        0x00

                             goto      start

                             org        0x08

                             retfie

                             org        0x18

                             retfie

start                    movlw kk

                             movwf lp_cnt

                             clrf         sum_hi,A

                             clrf         sum_lo,A

                             movlw upper(array)

                             movwf TBLPTRU,A

                             movlw high(array)

                             movwf TBLPTRH,A

                             movlw low(array)

                             movwf TBLPTRL,A

loop                     tblrd*+

                             btfsc      TABLAT,0,A

                             goto      next

                             movf     TABLAT,W,A

                             addwf   sum_lo,F,A

                             clrf         WREG,A

                             addwfc sum_hi,F,A

next                     decfsz   lp_cnt,F,A

                             goto      loop

                             nop

array   db   14,09,59,52,15,36,07,48,29,11

           db 15,22,13,94,45,16,47,28,49,23

           db 44,52,83,74,25,26,29,78,39,60

           db 31,42,33,34,04,36,37,38,39,41

           db 51,42,13,54,45,26,37,42,19,40

           len dw $-array
         
           short db ?

end start

            
end

#include <p18F8722.inc> radix dec sum_hi set 0x01 sum_lo set 0x00 lp_cnt set 0x02 kk equ D\'50\' org 0x00 goto start org 0x08 retfie org 0x18 retfie start
#include <p18F8722.inc> radix dec sum_hi set 0x01 sum_lo set 0x00 lp_cnt set 0x02 kk equ D\'50\' org 0x00 goto start org 0x08 retfie org 0x18 retfie start
#include <p18F8722.inc> radix dec sum_hi set 0x01 sum_lo set 0x00 lp_cnt set 0x02 kk equ D\'50\' org 0x00 goto start org 0x08 retfie org 0x18 retfie start

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site