Re: Question about jumps



Markus Pitha wrote:
Herbert Kleebauer wrote:

There is no need to put read only data in the data segment,
it is best placed in the code segment.

Ok, I'm still not absolutely sure about the differences between the
segments yet.

C uses NULL terminated strings, bur we are in assembly (and here we
decide ourselves how to terminate an string). Redirect the output to a
file and look at the hex dump of the file, then you will see, the 0 is
written as part of the string to stdout.

I see. I thought it's the same in assembly. So the last character of the
$-equ string tells assembler the end of the string, is that right?

Not the end of the string, but the length of the string:

textstart: dc "hello world"
textend:
textlength=textend-textstart

Or, instead of defining "textend" explicitly, you can use
the current location counter instead:

textlength=$-textstart

But then you have to write this immediately after the text,
so the current location counter has the same value as textend.


But for starting assembly programming in Linux, I would use
an assembler which can generate a flat outputfile (like NASM)
and don't use any linker . This way you really see what's
in your executable.

Here a simple example for a Linux executable. There are five
parts in the file:

ELF header: Don't modify this part, it is required by Linux to load
and execute the program.

code: Insert your code here, execution starts at the label main
(or whatever label is given in the ELF header)

constant data: Insert your read only data here

initialized data: Insert your initialized variables here

uninitialized data: Insert your uninitialized variables here

If you make a hex dump of the executable, you will see, there
is nothing than the bytes you explicitly defined in the source
code.



;===========================================================================

seg32
@=$08048000
code_offset=@@
code_addr:

;--------------------------- ELF header -----------------------------------

dc.l $464c457f,$00010101,0,0,$00030002,1,main,$34,0,0,$00200034,2,0
dc.l 1,code_offset,code_addr,code_addr,code_filez,code_memsz,5,4096
dc.l 1,data_offset,data_addr,data_addr,data_filez,data_memsz,6,4096

;--------------------------- code ------------------------------------------

main: move.l #1,r3 ; stdout
move.l #text,r2 ; text start
move.l #text_l,r1 ; text length
move.l #4,r0 ; write
trap #$80

move.l #0,r3 ; return code
move.l #1,r0 ; exit
trap #$80

;--------------------------- constant data ---------------------------------

text: dc.b "hello world",10
text_l=@-text

;---------------------------------------------------------------------------

code_filez=@@-code_offset
code_memsz= @-code_addr
even 4
@=(@+4095)/4096*4096+(@@\4096)
data_offset=@@
data_addr:

;--------------------------- initialized data ------------------------------

;var1: dc.l 1
;var2: dc.l 11

;--------------------------- uninitialized data ----------------------------

;var3: blk.l 1
;buf: blk.b 1000

;---------------------------------------------------------------------------

data_filez=@@-data_offset
data_memsz= @-data_addr

;===========================================================================
.



Relevant Pages

  • Re: Question about jumps
    ... Herbert Kleebauer wrote: ... it is best placed in the code segment. ... decide ourselves how to terminate an string). ... $-equ string tells assembler the end of the string, ...
    (alt.lang.asm)
  • Re: improve strlen
    ... The biggest optimization is that the code is bigger. ... each test string is tested ... The object on right side is type tree, ... The way I see it is that C is portable assembler, ...
    (comp.lang.asm.x86)
  • RE: SQL stored procedure executing twice
    ... I wasn't aware that DLookupwould execute the "domain" more than once. ... caused the stored procedure to execute twice. ... Dim stDocName As String ... My pass-thru query properties ...
    (microsoft.public.access.modulesdaovba)
  • Re: Macro code
    ... > I could replace any module in Berkeley Unix 4.4 whether in assembler or C." ... > create an HLL systems language for that architecture, ... was on static labeling of I/O buffers, and movement of data into static ... I/O buffer lables were string arrays. ...
    (comp.os.vms)
  • Re: Cannot execute DTS package
    ... > "Hermit Dave" wrote in message ... >> Whats happening is that it is trying to execute the Query with context ... >>> executing DTS packages from the ASP.NET: ... >>> String ServerPassword, DTSSQLServerStorageFlags Flags, String ...
    (microsoft.public.dotnet.framework.aspnet)