Re: LF: Request for an asm program


[Prev][Next][Index][Thread]

Re: LF: Request for an asm program



SonicWarez@aol.com wrote:
> 
> Can anyone please write me a fargo program that does the following:
> 
> tkes a 3 digit hexs number ie "fff"
> converts it to a twelve bit binary (4 digits each number)
> f=1111
> so the twelve bit would be
> "111111111111"
>   | |
> then drop the first two bits
> and get the 10 digit binary
> and then convert it to decimal
> so fff=1023

You don't convert it to hex, you directly mask of the two first bits.
If D0=the number (the input routine is the boring part to make) then

ANDI.W #$3F

would do the job for ya. To display it in hex, you would have to use
a routine for that. I've made one in BoulderDash, here it is:

; --------------------------------
;
;  Converts a number to a string
;
;   IN:  d0  - The number
;	 d1  - Number of digits
;	 a0  - Pointer to string
;   OUT: *a0 - The string (null-terminated)
;
; --------------------------------

ConvStr:
 adda.l  d1,a0
 clr.b	 (a0)
 subq.b  #1,d1
RepConv:
 divu	 #10,d0
 move.l  d0,d2
 swap    d2
 add.b	 #48,d2
 move.b  d2,-(a0)
 and.l	 #$FFFF,d0
 dbra	 d1,RepConv
 rts


This routine needs to know how many digits you want. You could change it
to the following if you only want as many digits as needed:

ConvStr:
 adda.l  d1,a0
 clr.b	 (a0)
 subq.b  #1,d1
RepConv:
 divu	 #10,d0
 move.l  d0,d2
 swap    d2
 add.b	 #48,d2
 move.b  d2,-(a0)
 and.l	 #$FFFF,d0
 beq Zero               ; Row added
 dbra	 d1,RepConv
Zero:                   ; Row added
 rts


The A0 register should before the routine point to a string in the memory,
declared like this:

str  ds.b 10     ; 10 = max size digits-1 (ie 9 digits max, a 0 at the end)

After the routine, A0 will point at the beginning of the string, so
just use romlib[puttext] to show it.

-- 
Jimmy Mårdell                "To tell you the truth I'm so damned tired
mailto:mja@algonet.se         A life-long leave is what I require
http://www.algonet.se/~mja    Rules, regulations try to form us
IRC: Yarin                    But not me, I'm gonna be enormous" /CRD



References: