LF: ASM Question...Help please...
[Prev][Next][Index][Thread]
LF: ASM Question...Help please...
Parham Sabetazm writes:
> Hi,
> I would appreciate it if someone could tell me how to write a for loop
> in 68k Assembly? I have the help card and the PDF file from Motorolla
> tester()
> Prgm
> ClrHome (Or ClrDraw, whichever clears the screen in Asm)
> For x,1,500
> Disp x
> Pause
> EndFor
> DelVar x
This is a rough translation that only goes to 50. It's unoptimized
but if you remove the call to idle_loop and change 50 to 999 or so,
it's fairly fast. Notice that counting backwards is easier in
assembly. I would normally use macros and EQUs for constants
to make life easier. This took me about 30 minutes to write
and debug, but someone who's had more experience could probably
do it much faster (still not as easy as TI Basic though).
-Kevin
khuber@mr.net
; ex.asm
; print 1-50
; no rights reserved - kth
@program prog_code,prog_name
prog_code:
jsr flib[clr_scr]
move.w #1,-(a7) ;#1 is 8x8 font
jsr romlib[set_font]
lea 2(a7),a7
move.w #1,x ; x=1
startloop:
move.l #$4440,a1 ; start of LCD mem (aka LCD_MEM)
move.l #$4440,a2
add.l #30*8,a2 ; 8 lines down
move.w #(((121-8)*30)/2)-1,d0 ; copy first 121 lines up
startcopy:
move.w (a2),(a1) ; copy a word (16 bits)
add.l #2,a1
add.l #2,a2
dbra.w d0,startcopy ; if d0 > 0,decrement & goto startcopy
move.l #$4440+112*30,a1 ;112 lines down
move.w #(15*8)-1,d0 ;8 rows
starterase:
move.w #0,(a1) ;clear
add.l #2,a1
dbra d0,starterase
move.w x,-(a7) ; push argument 1
pea numfmt(PC) ; format string
pea numtemp(PC) ; output buffer
jsr romlib[sprintf]
lea 10(a7),a7
move.w #0001,-(a7) ; color
pea numtemp(PC) ; Variable of string to print
move.w #112,-(a7) ; y
move.w #0,-(a7) ; x
jsr romlib[puttext] ; ROM call to puttext
lea 10(a7),a7 ; restore the stack pointer
jsr flib[idle_loop] ; wait for key
add.w #1,x ; x=x+1
cmp #50,x
ble startloop ; while x<=500 loop
rts
;*****************************************************
prog_name:
dc.b "example loop in ML",0
x dc.w 0
numfmt dc.b "%d",0
numtemp dc.b " ",0 ;big enough for 9999
;*************** End of Fargo program ****************
reloc_open
add_library romlib
add_library flib
reloc_close
end
References: