Hello,
I like to print 32bit integer numbers in assembly.
I read the example on codebase64.org but I don't get correct results. Can anyone help here?
https://codebase64.org/doku.php?id=base ... _to_string
Thank you in advance
Sven
PRINT 32-bit integer numbers
Moderator: Moderators
- MrSterlingBS
- Vic 20 Enthusiast
- Posts: 192
- Joined: Tue Jan 31, 2023 2:56 am
- Location: Germany,Braunschweig
- Mike
- Herr VC
- Posts: 4873
- Joined: Wed Dec 01, 2004 1:57 pm
- Location: Munich, Germany
- Occupation: electrical engineer
Re: PRINT 32-bit integer numbers
According to the example on codebase64.org, you need to set up the FAC in a certain fashion before the call to the VIC-20 equivalent of $B8D2, you obviously did not do that correctly.
If you want more help, post the code.
(and like with that other thread here, I strongly presume what you actually want is to test your 16x16->32 multiply works, as X of your XY problem. That output could also be done from BASIC. In any case, the (combination of) routines in the BASIC interpreter will print those 32-bit values >=1E10 in E notation which you likely do not want here. That again means, you studying how base conversion routines work in general and then trying to write such a routine from first principles and not via copy-and-paste is the key here.)
If you want more help, post the code.
(and like with that other thread here, I strongly presume what you actually want is to test your 16x16->32 multiply works, as X of your XY problem. That output could also be done from BASIC. In any case, the (combination of) routines in the BASIC interpreter will print those 32-bit values >=1E10 in E notation which you likely do not want here. That again means, you studying how base conversion routines work in general and then trying to write such a routine from first principles and not via copy-and-paste is the key here.)
- MrSterlingBS
- Vic 20 Enthusiast
- Posts: 192
- Joined: Tue Jan 31, 2023 2:56 am
- Location: Germany,Braunschweig
Re: PRINT 32-bit integer numbers
This is the code so far...
I used one of the multiply routines from Toby Lobster... only to play around with them.
I used one of the multiply routines from Toby Lobster... only to play around with them.
Code: Select all
CLRSCR equ $E55F
WRTF equ $E742 ; faster print
MVFACC equ $dba2
FLPINT equ $D1BF
STROUT equ $CB1E
PRTFIX equ $DDCD ; values form 0 to 65000 X - low; A - high
STACK equ $0100
*=$1201
dB $0B, $12, $0A, $00, $9E
dB $38, $31, $39, $32 ; SYS8192 = $2000
dB $00, $00, $00
*=$2000
;sei ; stop interrupts
jsr CLRSCR ; clear screen
jsr Primm
db "MULTIPLIER:",$1d,$00
ldx #15 ; low
stx aux
lda #0 ; high
sta aux+1
jsr PRTFIX
jsr Primm
db $0d,"MULTIPLICAND:",$1d,$00
ldx #232 ; low
stx acc
lda #3 ; high
sta acc+1
jsr PRTFIX
; code from the book VIC-20 MACHINE LANGUAGE GUIDE Abacus Software
lda #$FF
sta $9129 ; decrements every 256 µS ; 4 cycles
lda #$00
sta $9128 ; decrements every µS ; 4 cycles
; ************** Start Counter with 10 Cycles ********************
jsr mult
; ***************************************************************************************
lda $9128 ; low
ldx $9129 ; high
sta $FB ; low
stx $FC ; high
; ************** Stop Counter ********************
jsr Primm
db $0d,$0d,"PRODUCT:",$1d,$00
;ldx #9 ;result_low
;lda #0
;jsr PRTFIX
;lda acc
;sta integer+3
ldy acc
;sta integer+2
ldx ext
; sta integer+1
lda ext+1
;sta integer
sec
jsr $cf87 ; sets mantissa to 00yyxxaa
jsr $cf7e ; set rest of FAC1 and JMP to $b8d2
;cld
;ldy integer
;lda integer+1
jsr $D391
jsr $DBA2
jsr $DDDD
ldy #>STACK
lda #<STACK
jsr $CB1E
lda #$FF
sbc $FC
sta $FC
lda #$FF
sbc $FB
sbc #$09
sta $FB
jsr Primm
db $0d,$0d,$0d,$12,"CYCLES:",$1d,$92,$00
ldx $FB ; low
lda $FC ; high
jsr PRTFIX
jmp * ; infinity jump
integer:
db $00,$00,$00,$00
Primm:
pla
sta $03
pla
sta $04
X10D6:
inc $03
bne X10DC
inc $04
X10DC:
ldy #$00
lda ($03),y
beq X10E7
jsr WRTF
bcc X10D6
X10E7:
lda $04
pha
lda $03
pha
rts
;*************************************
; for testing
cld
ldy #>acc
lda #<ext
jsr $D391
;jsr $DBA2
jsr $DDDD
ldy #>STACK
lda #<STACK
jsr $CB1E
jmp *
FPNUM:
byte $8a,$7a,$00,$00,$00
;********************************
; mult2.a
; from The Merlin 128 Macro Assembler disk, via 'The Fridge': http://www.ffd2.com/fridge/math/mult-div.s
; with an optimisation for speed (changing pha/pla to tax/txa)
;
; 16 bit x 16 bit unsigned multiply, 32 bit result
; Average cycles: 578
; 33 bytes
; acc*aux -> [acc,acc+1,ext,ext+1] (low,hi) 32 bit result
aux = $02 ; 2 bytes input1
acc = $04 ; 2 bytes input2 } result
ext = $06 ; 2 bytes }
;* = $0200
; (acc, acc+1, ext, ext+1) = (aux, aux+1) * (acc, acc+1)
mult:
lda #0 ; A holds the low byte of ext (zero for now)
sta ext+1 ; high byte of ext = 0
ldy #17 ; loop counter. Loop 17 times.
clc ;
loopmult:
ror ext+1 ; }
ror ; }
ror acc+1 ; } acc_ext >> 1
ror acc ; }
bcc mul2 ; skip if carry clear
clc ; }
adc aux ; }
tax ; remember A }
lda aux+1 ; } ext += aux
adc ext+1 ; }
sta ext+1 ; }
txa ; recall A
mul2:
dey ; decrement loop counter
bne loopmult ; loop back if not done yet
sta ext ;
rts ;
- Mike
- Herr VC
- Posts: 4873
- Joined: Wed Dec 01, 2004 1:57 pm
- Location: Munich, Germany
- Occupation: electrical engineer
Re: PRINT 32-bit integer numbers
That part ...MrSterlingBS wrote:This is the code so far... I used one of the multiply routines from Toby Lobster... only to play around with them.
... would anyhow only convert the 24-bit value contained in Y (bits 16..23), X (bits 8..15) and A (bits 0..7), with the top-most byte of the assumed 32-bit value being 0.Code: Select all
sec jsr $cf87 ; sets mantissa to 00yyxxaa jsr $cf7e ; set rest of FAC1 and JMP to $b8d2
Once again, I strongly recommend you fetch some text book, look up how base conversion works in general (hint: repeated division by 10 until you get a zero result, storing away the remainders right-to-left - alternatively, a table-based approach, repeatedly subtracting powers of 10) and then implement that routine fully by yourself. Those examples you find on the internet need you to set up their parameters in a given way and call routines in the BASIC interpreter in yet another given way. Randomly feeding the routines with data and calling the routines in a hap-hazard fashion in the hope one combination gets it right is not the way to go here!
Re: PRINT 32-bit integer numbers
The one I posted here should be easily extendible to any resonable bit width: http://sleepingelephant.com/ipw-web/bul ... 85#p114085
- MrSterlingBS
- Vic 20 Enthusiast
- Posts: 192
- Joined: Tue Jan 31, 2023 2:56 am
- Location: Germany,Braunschweig
Re: PRINT 32-bit integer numbers
I think i have it. Thanks for the tipps.