bizarre offset problems when loading assembly bins from basic (Development Foros MSX)MSX Resource Center MSXdev 2008 - MSX1 development bonanza!           
                       
English Nederlands Español Português Russian                  
 Noticias
   Página principal
  Almacén de noticias
  Temas de noticias

 Recursos
   Foros MSX
  Artículos
  Analisis
  Informe de ferias/RUs
  Álbum de fotos
  Ferias y encuentros
  Encuestas
  Enlaces
  Buscar

 Software
   Descargas
  Tienda Online

 MRC
   Quiénes somos
  Únete a nuestro equipo
  Donar
  Políticas
  Contacta con nosotros
  Enlázanos
  Estadísticas

 Buscar
 
  

  

 Login
 

Login

Contraseña




¿Aún no tienes una cuenta? ¡Conviértete en miembro del MSX Resource Center! ¡Únete a nosotros!.


 Estadísticas
 

Hay 85 invitados y 1 miembro en línea

Eres un usuario anónimo.
 

Foros MSX


Foros MSX

Development - bizarre offset problems when loading assembly bins from basic

Autor

bizarre offset problems when loading assembly bins from basic

wur
msx friend
Mensajes: 8
Publicado: Junio 12 2005, 08:08   
Hi,

I'm starting to code for the MSX/Z80 for the first time, so bear with me. I'm using the tniasm cross-compiler, and loading from MSX-Basic

Can someone tell me why my version of "puts()" works with this code, with all the weird offsets:


org $8800

db $fe
dw $880A ; notice this is different from the org addr
dw $8850
dw $880A

jp main

hca: db "HCAFHKJSKJHFDKSJ", $0

main: ld bc, hca + 3
call &puts

.end: ret


puts: ld a, (bc)

cp 0
jr nz, $+3
ret
call $a2
inc bc
jp puts

.end: ret


But it doesn't work here:

org $8800

db $fe
dw $8800
dw $8850
dw $8800

jp main

hello: db "Hello world!", $0


main: ld bc, &hello
call &puts

.end: ret


puts: ld a, (bc)

cp 0
jr nz, $+3
ret
call $a2
inc bc
jp puts

.end: ret


I've noticed the first example doesn't always work; ie, if you change the string length, it halts (obviously, the jp main isn't going in the right place.) I'm thinking of giving up on Basic and coding only under MSX-DOS....

thanks,
BH
BiFi
msx guru
Mensajes: 3142
Publicado: Junio 12 2005, 08:46   
to make a binfile like that, you should use this:

db $fe
dw start,end,execute

org $8800

start: ;your code

execute: ;where your code starts

end: ;end of your code

sjoerd
msx addict
Mensajes: 444
Publicado: Junio 12 2005, 08:52   
First: use SjASM!

And use dos instead of basic.

If you like to use basic, make sure the header is right.
org $8800

db $fe
dw begin
dw eind
dw hop

begin
hop
 jp main

hello: db "Hello world!", $0


begin:
main: ld bc, &hello
 cal puts

.end: ret


puts: ld a, (bc)

 cp 0
 jr nz, $+3  ; uhum? why not use ret z?
 ret
 call $a2
 inc bc     ; i've got no idea what this is suppose to mean :)
 jp puts

.end: ret
eind

sjoerd
msx addict
Mensajes: 444
Publicado: Junio 12 2005, 08:53   


What BiFi said.

But use SjASM!
d-fader
msx lover
Mensajes: 71
Publicado: Junio 12 2005, 10:12   
use chaos assembler!

*lol*
[D-Tail]

msx guru
Mensajes: 2994
Publicado: Junio 12 2005, 11:59   
Compass all the way!
wolf_

msx legend
Mensajes: 4663
Publicado: Junio 12 2005, 12:58   
Use basic, and read thousands of hex values from datalines
pitpan
msx master
Mensajes: 1368
Publicado: Junio 12 2005, 13:10   
You can also use asMSX that makes the things even easier:

.page 2 ; this is the same as .org 8000h - you can use any other address between 8000h and FFFFh
.basic
.start INIT

INIT:
; put your code here

This will generate a Basic BIN file ready to load in your MSX. And using MSXwav (included in asMSX distribution) you can convert it to WAV and load it into MSX without disk drive. I hope this helps!

[ADVERT]
You can download it at http://www.robsy.net/asmsx11c.zip
[/ADVERT]

manuel
msx guru
Mensajes: 3381
Publicado: Junio 12 2005, 13:18   
Use Pasmo! ;-)

WHATEVER!
AuroraMSX

msx master
Mensajes: 1231
Publicado: Junio 15 2005, 11:18   
The ORG sets the location counter to the given address: $8800 in your case.
The 7 byte header at the start of your code is code too, takes up seven bytes, so your actual routine will start at location $8807, not at $8800. The calculated address for eg. "hca" is $8007 + the size of the "jp main" code == $800A.

Important is, that the addresses computed/used at assembly time are not neccessarily related to the addresses at which the code will be loaded at run time! The address at which the code is loaded is defined by the addresses in the header. Now, your header tells BASIC to load the code at $880A, so at $880A the "jp main" will show up and "hca" will be at $880D. That is why your code needs that "+3" on the "ld bc,hca+3" statement. I really wonder how it is possible that that routine still works, though, since all computed addresses for calls and jumps are 3 bytes off

Now, the best thing to do is
(a) put the ORG after the header, so the header doesn't influence the start
(b) build the header using symbols instead of absolute addresses

Like this:

        db    $FE
        dw    start
        dw    end
        dw    exec

        org   $8800
start:
exec:
        ; insert code here
end:


Oh, and use gen80 or m80
 
 







(c) 1994 - 2008 Fundación MSX Resource Center. MSX es una marca registrada de MSX Licensing Corporation