bizarre offset problems when loading assembly bins from basic (Development MSX Fora)MSX Resource Center            
            
English Nederlands Espa�ol Portugu�s Russian         
 Nieuws
   Voorpagina
  Nieuws archief
  Nieuws onderwerpen

 Informatie
   MSX Fora
  Artikelen
  Recensies
  Beursverslagen
  Fotoreportages
  Beurzen en meetings
  Enquêtes
  Links
  Zoek

 Software
   Downloads
  Webshop

 MRC
   Wie we zijn
  Kom bij ons team
  Doneren
  Policies
  Contact met het MRC
  Link naar Ons
  Statistieken

 Zoek
 
  

  

 Login
 

Gebruikersnaam

Wachtwoord




Ben je nog niet lid? Klik hier en word MSX vriend!


 Statistieken
 

Er zijn 54 gasten en 6 MSX vrienden online

Je bent een anonieme bezoeker.
 

MSX Fora


MSX Fora

Development - bizarre offset problems when loading assembly bins from basic

Schrijver

bizarre offset problems when loading assembly bins from basic

wur
msx friend
Berichten: 8
Geplaatst: 12 Juni 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
Berichten: 3142
Geplaatst: 12 Juni 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
Berichten: 450
Geplaatst: 12 Juni 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
Berichten: 450
Geplaatst: 12 Juni 2005, 08:53   


What BiFi said.

But use SjASM!
d-fader
msx lover
Berichten: 71
Geplaatst: 12 Juni 2005, 10:12   
use chaos assembler!

*lol*
[D-Tail]

msx guru
Berichten: 3019
Geplaatst: 12 Juni 2005, 11:59   
Compass all the way!
wolf_
online

msx legend
Berichten: 4777
Geplaatst: 12 Juni 2005, 12:58   
Use basic, and read thousands of hex values from datalines
pitpan
msx master
Berichten: 1389
Geplaatst: 12 Juni 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
online
msx guru
Berichten: 3531
Geplaatst: 12 Juni 2005, 13:18   
Use Pasmo! ;-)

WHATEVER!
AuroraMSX

msx master
Berichten: 1260
Geplaatst: 15 Juni 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 Stichting MSX Resource Center. MSX is een trademark van MSX Licensing Corporation.