print numbers in ASM

By janghang

Master (129)

Аватар пользователя janghang

19-03-2011, 21:18

Hi,

I am studying msx asm. We have a simple z-80 ASM code like this:

               org 8000h
               ld hl, regi
               ld (hl), a
               inc hl
               ld a, b
               ld (hl), a
               inc hl
               ld a, c
               ld (hl), a
               inc hl
               ld a, d
               ld (hl), a
               inc hl
               ld a, e
               ld (hl), a
               ret
        regi: defs 5

I want to display the final value of 'regi' on screen. How can I change this asm code to do that?

I tried to port some spring display code using ChGet and ChPut, but it didn't work.

Thank you!.

Для того, чтобы оставить комментарий, необходимо регистрация или !login

By norakomi

Paragon (1136)

Аватар пользователя norakomi

19-03-2011, 22:16

shorter:

               org 8000h
               ld ix, regi
               ld (ix+0), a
               ld (ix+1), b
               ld (ix+2), c
               ld (ix+3), d
               ld (ix+4), e
               ret
        regi: defs 5

By WORP3

Paladin (864)

Аватар пользователя WORP3

19-03-2011, 22:55

How do you want to print it on the screen, as a string, integer hex or .... ?
Do you want to use a bios call or directly into video ram ?
Are you going to print it to a text or graphical screen ?

By janghang

Master (129)

Аватар пользователя janghang

19-03-2011, 23:09

shorter:

               org 8000h
               ld ix, regi
               ld (ix+0), a
               ld (ix+1), b
               ld (ix+2), c
               ld (ix+3), d
               ld (ix+4), e
               ret
        regi: defs 5

Thanks. I just learned how to use the index register. Smile

By janghang

Master (129)

Аватар пользователя janghang

19-03-2011, 23:11

How do you want to print it on the screen, as a string, integer hex or .... ?
Do you want to use a bios call or directly into video ram ?
Are you going to print it to a text or graphical screen ?

Good point! either way is fine, but if possible, could you please let me know how to print it as both a text and graphics object?

Thank you!

By ARTRAG

Enlighted (6923)

Аватар пользователя ARTRAG

19-03-2011, 23:55

Which screen mode do you use?

By janghang

Master (129)

Аватар пользователя janghang

20-03-2011, 03:33

Which screen mode do you use?

Any mode would be fine: Screen 0 or 1
Thanks!

By Metalion

Paragon (1622)

Аватар пользователя Metalion

21-03-2011, 09:23

shorter:

               org 8000h
               ld ix, regi
               ld (ix+0), a
               ld (ix+1), b
               ld (ix+2), c
               ld (ix+3), d
               ld (ix+4), e
               ret
        regi: defs 5

Shorter but 58% slower than :

               org 8000h
               ld hl, regi
               ld (hl), a
               inc hl
               ld (hl), b
               inc hl
               ld (hl), c
               inc hl
               ld (hl), d
               inc hl
               ld (hl), e
               ret
        regi: defs 5

109 T-states for the IX version, 69 T-states for that HL version ...
That's the beauty of ASM : there is a lot of different solutions for the same problem.
And it's up to the developper to choose what he wants : easiest readable code, fastest code, most flexible code, ...

Anyway, to display a value in screen 0 or 1, just use CHPUT ($002A).
You just have to load the value in the a register and make a call to CHPUT.
Of course, the value has to be an ASCII value.

So it might be :

               org 8000h
               ld hl, regi
               ld (hl), a
               inc hl
               ld (hl), b
               inc hl
               ld (hl), c
               inc hl
               ld (hl), d
               inc hl
               ld (hl), e

               ld a,e
               call $002A
               ret
        regi: defs 

Or even

               ...
               ld a,e
               jp $002A
        regi: defs

You can jump to CHPUT, because at the end of it, there will be a RET instruction, thus achieving the return to your first call.