Re: [9fans] Hello Assembly - Plan9

This is a discussion on Re: [9fans] Hello Assembly - Plan9 ; Thanks everybody (especially Jim and Charles), I got this to work. Here's the final program: DATA string +0(SB)/8, $"Hello\n\z\z" GLOBL string +0(SB), $8 TEXT _main+0(SB), 1, $0 MOVL $1, 4(SP) MOVL $string +0(SB), 8(SP) MOVL $7, 12(SP) MOVL $-1, 16(SP) ...

+ Reply to Thread
Results 1 to 9 of 9

Thread: Re: [9fans] Hello Assembly

  1. Re: [9fans] Hello Assembly

    Thanks everybody (especially Jim and Charles), I got this to work.
    Here's the final program:

    DATA string<>+0(SB)/8, $"Hello\n\z\z"
    GLOBL string<>+0(SB), $8

    TEXT _main+0(SB), 1, $0

    MOVL $1, 4(SP)
    MOVL $string<>+0(SB), 8(SP)
    MOVL $7, 12(SP)
    MOVL $-1, 16(SP)
    MOVL $-1, 20(SP)

    MOVL $51, AX
    INT $64

    MOVL $string<>+0(SB), 4(SP)
    MOVL $8, AX
    INT $64

    Jim pointed out that using RET was incorrect as the instruction
    wouldn't know where to get back to. Calling exits() instead, works.

    Plan 9 gets more and more exciting for me, everyday
    Thanks again!

    Cheers,
    Anant

  2. Re: [9fans] Hello Assembly

    On Feb 9, 2008, at 4:15 PM, Anant Narayanan wrote:

    > DATA string<>+0(SB)/8, $"Hello\n\z\z"


    Why are there two \zs? Shouldn't one be enough?



  3. Re: [9fans] Hello Assembly

    >> DATA string<>+0(SB)/8, $"Hello\n\z\z"
    >
    > Why are there two \zs? Shouldn't one be enough?


    One should be enough, but 8c -S does two \z's (probably to pad it out
    to exactly 8 bytes). It works either way, since the length we pass as
    an argument to pwrite is still $7.

    Regards,
    Anant

  4. Re: [9fans] Hello Assembly

    > Thanks everybody (especially Jim and Charles), I got this to work.
    > Here's the final program:
    >
    > DATA string<>+0(SB)/8, $"Hello\n\z\z"
    > GLOBL string<>+0(SB), $8
    >
    > TEXT _main+0(SB), 1, $0
    >
    > MOVL $1, 4(SP)
    > MOVL $string<>+0(SB), 8(SP)
    > MOVL $7, 12(SP)
    > MOVL $-1, 16(SP)
    > MOVL $-1, 20(SP)
    >
    > MOVL $51, AX
    > INT $64
    >
    > MOVL $string<>+0(SB), 4(SP)
    > MOVL $8, AX
    > INT $64
    >
    > Jim pointed out that using RET was incorrect as the instruction
    > wouldn't know where to get back to. Calling exits() instead, works.
    >
    > Plan 9 gets more and more exciting for me, everyday
    > Thanks again!
    >
    > Cheers,
    > Anant


    I've always thought variables and such went at the bottom... or
    is that just m68k asm?

    John


  5. Re: [9fans] Hello Assembly

    > I've always thought variables and such went at the bottom... or
    > is that just m68k asm?
    >
    > John


    you can put them anywhere. there's no typechecking in assembly
    and the linker doesn't care.

    - erik


  6. Re: [9fans] Hello Assembly

    >> I've always thought variables and such went at the bottom... or
    >> is that just m68k asm?
    >>
    >> John

    >
    > you can put them anywhere. there's no typechecking in assembly
    > and the linker doesn't care.
    >
    > - erik


    Ok, maybe that was just a style thing they taught us.

    John


  7. Re: [9fans] Hello Assembly

    >>> I've always thought variables and such went at the bottom... or
    >>> is that just m68k asm?
    >>>
    >>> John

    >>
    >> you can put them anywhere. there's no typechecking in assembly
    >> and the linker doesn't care.
    >>
    >> - erik

    >
    > Ok, maybe that was just a style thing they taught us.
    >
    > John


    Most old school programmers put the variables at the bottom so the
    assembled binary could start executing from the top avoiding the need
    to jmp around the data. Even early C programs did this. Check out
    dmr's old C compilers. The globals were at the end of the file.

    Early PDP-11 binaries could be loaded with the a.out headers intact
    and run. The magic number was a branch relative eight words
    instruction and would jump the header.


  8. Re: [9fans] Hello Assembly

    On Mon, Feb 11, 2008 at 11:43:08AM -0500, erik quanstrom wrote:
    > > I've always thought variables and such went at the bottom... or
    > > is that just m68k asm?

    >
    > you can put them anywhere. there's no typechecking in assembly
    > and the linker doesn't care.
    >


    When I started programming (so long ago that assembly and Fortran
    were basically the only games in town) we always put the data at
    the end--it just seemed fitting somehow. Later, the best
    practice became to put them at the beginning on the grounds that
    the data wouldn't move as changes where made to the program; in
    those days, all manner of strange things happened like programs
    that knew where the data portion of other programs lived. If
    nothing else, it made the (very crude) dumps easier to work with.

    jcs

  9. Re: [9fans] Hello Assembly

    It's also that x86 segments memory into code, data, and stack, so you
    can have

    .code
    OR EAX, EAX // produces less binary than CMP EAX, 0; JE X
    JZ X
    JMP Y
    Y:
    .data
    str DB 'less\z'
    .code
    // ...
    .data
    .code
    .stack
    .code
    .data

    On Feb 11, 2008, at 2:41 PM, Jon Snader wrote:

    > On Mon, Feb 11, 2008 at 11:43:08AM -0500, erik quanstrom wrote:
    >>> I've always thought variables and such went at the bottom... or
    >>> is that just m68k asm?

    >>
    >> you can put them anywhere. there's no typechecking in assembly
    >> and the linker doesn't care.
    >>

    >
    > When I started programming (so long ago that assembly and Fortran
    > were basically the only games in town) we always put the data at
    > the end--it just seemed fitting somehow. Later, the best
    > practice became to put them at the beginning on the grounds that
    > the data wouldn't move as changes where made to the program; in
    > those days, all manner of strange things happened like programs
    > that knew where the data portion of other programs lived. If
    > nothing else, it made the (very crude) dumps easier to work with.
    >
    > jcs



+ Reply to Thread