Mercurial > hg > Members > kono > nitros9-code
view lib/alib/dec_bin.as @ 2981:9550602c9a0b
sierra/objs_lsl/mnln.asm: Use division quotient, not remainder
It calls a routine twice to make a division (L125C) but doesn't check
the right register for the result. The result is returned in reg U and
the remainder in reg D but the procedure expect the result to be returned
in reg D. The divison routine seems to be correct because it is properly
used elsewhere in the code.
Patch by Guillaume Major and Robert Gault.
author | Guillaume Major <guillaume.major@gmail.com> |
---|---|
date | Sat, 12 Apr 2014 15:30:03 +0200 |
parents | 03f26e88b809 |
children |
line wrap: on
line source
**************************************** * DECIMAL to BINARY conversion routine * OTHER MODULES NEEDED: DECTAB$, IS_TERMIN * ENTRY: X = start of asci decimal string terminated by * a space, comma, CR or null. * EXIT: D = binary value * CC carry set if error (too large, not numeric) * Y = terminator or error char. nam Convert Decimal String to Binary ttl Assembler Library Module section .bss nega rmb 1 endsect section .text DEC_BIN: clra set result to 0 clrb pshs a,b,x leas -1,s temp variable clr nega,u ldb ,x+ cmpb #'- bne decbn15 stb nega,u decbn1 LDB ,X+ get a digit decbn15 LBSR IS_DIGIT bne decbn3 end of string... INCA bump string len BRA decbn1 loop for whole string decbn3 lbsr IS_TERMIN valid terminator? bne error ok TSTA length = 0? BEQ error yes, error CMPA #6 more than 6 chars? BHI error yes, error ldx 3,s get start of string again PSHS A lda ,x cmpa #'- bne decbn35 leax 1,x decbn35 LDA #5 max length SUBA ,S+ adjust for offset ASLA 2 bytes per table entry LEAY DECTAB$,PCR addr of conversion table LEAY A,Y add in offset for actual len decbn4 LDA ,X+ get a digit SUBA #$30 strip off ASCII BEQ decbn6 zero, skip sta ,s save digit=# of adds LDD 1,S get binary data decbn5 ADDD ,Y add in table value BCS error past 0, too big DEC ,S count down digit size BNE decbn5 loop til 0 STD 1,S save binary data decbn6 LEAY 2,Y next entry tst 1,y end of table? BNE decbn4 loop til done clr ,s+ clean up and clear carry bra exit error clr 0,s force data = 0 clr 1,s com ,s+ clean up and set carry exit tfr x,y end of string/error char puls a,b,x bcs leave tst nega,u beq leave subd #$0001 coma comb andcc #$FE leave rts endsect