Welcome, Guest. Please login or register.

Author Topic: Few asm things I found by experimentation and would like confirmation  (Read 1917 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show only replies by Jose
Hey. You know when you do things imitating what you saw/read and stuff tends to work right? Well, I allways want to mess things up and experiment with weird ways to understand how they work if that's not documented or something (at least in the assembler docs). The bellow stff is some things I found out using asm-one and asm-pro. I think they're right but If somwone can confirm and share their experience please do so.
Please refer to the numbers for simplicity....

1- using the dc asm directive
can't define constants before the end of the program.. If I made a dc.b (didn't try with .w or .l), even with an align after (of course..) debbuger reported  error in the instructions after. Errors disabppeared after I deleted the dc.b declarationj. I even tried to use the asm directive section code, after the dc,  thinking that the asm had automatically changed the section but no luck...
So is this a given... you can't use dc unless in the end of the programs, and is this the same for all assemblers?

2- section assembler directive
asm- one (and asm-pro I assume, diddn't try) accepts data, code and bss. While I see what it is, I can't see why the different section defenitions  exist. Shouldn't the assembler distinguish bettwee them? Do they have to be in a particular order(and could this be the reason for my previous errors in the debugger I described in 1-?
can they be miixed? Are all assembler the same?
by the way, dss is declare storage section right?
 
3-  offset asm directive
from what I tried, only changes the values of labels(adding the offset) for constant declerations at the and of the program. Does nothing if used before the labels of the program instructions. ..


I tied to find more references to this but tutorial in general assume that the program has a cetain structore or sometihng, so I wanted to know if one can do this or not...
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline u_jakobsen

  • Newbie
  • *
  • Join Date: Dec 2003
  • Posts: 8
    • Show only replies by u_jakobsen
Re: Few asm things I found by experimentation and would like confirmation
« Reply #1 on: January 29, 2004, 07:16:02 AM »
Answers in order:
1:Your debugger reports an error simply because it cant guess what opcode is next. And yes ofcourse you can insert data whereever you want, except that the program counter must not be able to run into these sections.
Example of legal use:

j:
        moveq.l  #1,d0
        rts
number:        dc.w 42
j2:
       moveq.l  #2,d0
       rts


and illegal use:

j:
        moveq.l  #1,d0
number:        dc.w 42
       rts



Disassemble starting from a point after your data for instance at label which points at CODE and not DATA!!! Or even better: Don't make any mistakes. ;-)

2: With the very, very old tools you could choose to overlay sections, thus saving memory. A further use was the fact that Asm-one was based on K-Seka 68K assembler which also had products used on other platforms where you couldn't mix code and data. They can be mixed, except I think the first one has to be code (it is the entrypoint for the program).
But if you examine most assembly-programs they usually only contain a code section, since it can be used for all purposes but one: a data section can be forced to load into chip-mem.

3: Don't use this directive. It serves no sensible purpose, unless you are planning on developing hardware banging trackloaded demos.

Keep the spirit alive.......
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Few asm things I found by experimentation and would like confirmation
« Reply #2 on: January 29, 2004, 09:24:28 AM »
@Jose
Quote

asm- one (and asm-pro I assume, diddn't try) accepts data, code and bss. While I see what it is, I can't see why the different section defenitions exist.

Code and Data sections function the same, it makes no difference to loader.

However, BSS section can only contain empty space (all 0), thus cannot contain initial code or data.

Quote
Shouldn't the assembler distinguish bettwee them?

Some assemblers know how to put code to code section and data to data section, and even empty variables to bss. Usually this is done manually, though.

Quote
Do they have to be in a particular order(and could this be the reason for my previous errors in the debugger I described in 1-?

No. The only obvious limitation is that BSS can't be the first hunk (since empty space assembles to ori.b #0,d0, and the execution of bss hunk would just fall off the end of the world).

Quote

can they be miixed?

Sure.

Quote
Are all assembler the same?

No. Some assemblers set artificial limitations.

@u_jakobsen
Quote
But if you examine most assembly-programs they usually only contain a code section, since it can be used for all purposes but one: a data section can be forced to load into chip-mem.

CODE sections can be forced to load into chip-mem aswell.
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show only replies by Jose
Re: Few asm things I found by experimentation and would like confirmation
« Reply #3 on: January 29, 2004, 07:07:11 PM »
Ahh!!...sounds so trivial when you get it! ;-)
 So , BSS probably stands for blank storage section or something like that....
Cool, the time I dedicate to this is almost zero,  but  I'm getting there :-o
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline PiR

  • Full Member
  • ***
  • Join Date: Apr 2003
  • Posts: 148
    • Show only replies by PiR
Re: Few asm things I found by experimentation and would like confirmation
« Reply #4 on: January 30, 2004, 11:52:53 AM »
Hi

I decided to clearify some things.
A dc is just introducing constant, so it is NOT ILLEGAL to use it anywhere, including inside the code, if you can predict what numerical value should be put in the place (I mean you can write whiole program code as dc, if you want and know the values).
Even more - if you use optimizing assembler, and want to ensure that your command won't be changed (for example for sake of code checksum calculations) it can be the only choice to insert opcode as dc.
The thing that you observed is something different - it is the problem of disassembling of code with variable length instructiions. If command can have extension words, you can never be sure if the current word is really new instruction, or extension word of previous. It is something that doesn't exist in PPC, as there every command is always exactly 32-bit wide.

Code and Data sections are used for logical structure of executable. In general, if you want to creatre duplication of the process you have to duplicate the data sections (as these can be written by each process and should be visible only for the process that owns it), but both can share the same code section, as the code is expected not to change during execution). For these reasons constants (like strings for example) are very often attached at the end of code segment by the compilers, as these shouldn't be modified also.
However all of this is not a rule on Amiga, as the system doesn't protect the memory for the owner process only, and you can often see code modifications (like writing pointers to code for jump instructions, while patching libraries...).
However each section (code, data, bss) can have flag to be placed in: FAST-ONLY, CHIP-ONLY, or ANY memory.

And the last thing: BSS sections are just declared and ensured to be filled with zeros, but these are not written explicitly in the code, so doesn't take a space in executable file. Normally, if you write zero in a data section it is written as zero.
Except for one situation: code and data section can be declared to occupy more space than the data they have. This additional data is also initialized to zero. This can be considered as attached BSS to each Data and Code.
Example:

Section data, data

dc.l 1 ; value
ds.l 1 ; declare space, but in the middle, so it is equal to dc.l 0
dc.l 3 ; value
ds.l 1 ; this is declared, but won't take ANY space in the executable, as it will simply extend data section.


I hope I described it clearly enough. If not - let me know.