1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-27 00:29:31 +00:00
cc65/libsrc/runtime/lconvert.s
uz 53dd513176 This commit was generated by cvs2svn to compensate for changes in r2,
which included commits to RCS files with non-trunk default branches.


git-svn-id: svn://svn.cc65.org/cc65/trunk@3 b7a2c559-68d2-44c3-8de9-860c34a00d81
2000-05-28 13:40:48 +00:00

89 lines
1.1 KiB
ArmAsm

;
; Ullrich von Bassewitz, 05.08.1998
;
; CC65 runtime: long conversion routines
;
;
; Convert TOS from long to int by cutting of the high 16bit
;
.export tosint, tosulong, toslong, axulong, axlong
.import incsp2, decsp2
.importzp sp, sreg
tosint: pha
ldy #0
lda (sp),y ; sp+1
ldy #2
sta (sp),y
ldy #1
lda (sp),y
ldy #3
sta (sp),y
pla
jmp incsp2 ; Drop 16 bit
;
; Convert TOS from int to long
;
tosulong:
pha
jsr decsp2 ; Make room
ldy #2
lda (sp),y
ldy #0
sta (sp),y
ldy #3
lda (sp),y
ldy #1
sta (sp),y
lda #0 ; Zero extend
toslong2:
iny
sta (sp),y
iny
sta (sp),y
pla
rts
toslong:
pha
jsr decsp2 ; Make room
ldy #2
lda (sp),y
ldy #0
sta (sp),y
ldy #3
lda (sp),y
bmi toslong1
ldy #1
sta (sp),y
lda #$00 ; Positive, high word is zero
bne toslong2
toslong1:
ldy #1
sta (sp),y
lda #$FF
bne toslong2
;
; Convert AX from int to long in EAX
;
axulong:
ldy #0
sty sreg
sty sreg+1
rts
axlong: cpx #$80 ; Positive?
bcc axulong ; Yes, handle like unsigned type
ldy #$ff
sty sreg
sty sreg+1
rts