9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* Re: [9fans] Hello Assembly
       [not found] <ead6208b996760a9eb2eeccb8c431b12@plan9.bell-labs.com>
@ 2008-02-09 21:15 ` Anant Narayanan
  2008-02-09 21:27   ` Pietro Gagliardi
  2008-02-11 16:36   ` john
  0 siblings, 2 replies; 37+ messages in thread
From: Anant Narayanan @ 2008-02-09 21:15 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

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


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-09 21:15 ` [9fans] Hello Assembly Anant Narayanan
@ 2008-02-09 21:27   ` Pietro Gagliardi
  2008-02-10  8:30     ` Anant Narayanan
  2008-02-11 16:36   ` john
  1 sibling, 1 reply; 37+ messages in thread
From: Pietro Gagliardi @ 2008-02-09 21:27 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 148 bytes --]

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?


[-- Attachment #2: Type: text/html, Size: 601 bytes --]

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-09 21:27   ` Pietro Gagliardi
@ 2008-02-10  8:30     ` Anant Narayanan
  0 siblings, 0 replies; 37+ messages in thread
From: Anant Narayanan @ 2008-02-10  8:30 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

>> 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


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-09 21:15 ` [9fans] Hello Assembly Anant Narayanan
  2008-02-09 21:27   ` Pietro Gagliardi
@ 2008-02-11 16:36   ` john
  2008-02-11 16:43     ` erik quanstrom
  1 sibling, 1 reply; 37+ messages in thread
From: john @ 2008-02-11 16:36 UTC (permalink / raw)
  To: 9fans

> 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


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-11 16:36   ` john
@ 2008-02-11 16:43     ` erik quanstrom
  2008-02-11 16:45       ` john
  2008-02-11 19:41       ` Jon Snader
  0 siblings, 2 replies; 37+ messages in thread
From: erik quanstrom @ 2008-02-11 16:43 UTC (permalink / raw)
  To: 9fans

> 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


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-11 16:43     ` erik quanstrom
@ 2008-02-11 16:45       ` john
  2008-02-11 19:41       ` Jon Snader
  1 sibling, 0 replies; 37+ messages in thread
From: john @ 2008-02-11 16:45 UTC (permalink / raw)
  To: 9fans

>> 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


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-11 16:43     ` erik quanstrom
  2008-02-11 16:45       ` john
@ 2008-02-11 19:41       ` Jon Snader
  2008-02-11 19:49         ` Pietro Gagliardi
  1 sibling, 1 reply; 37+ messages in thread
From: Jon Snader @ 2008-02-11 19:41 UTC (permalink / raw)
  To: 9fans

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


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-11 19:41       ` Jon Snader
@ 2008-02-11 19:49         ` Pietro Gagliardi
  0 siblings, 0 replies; 37+ messages in thread
From: Pietro Gagliardi @ 2008-02-11 19:49 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

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


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-09 16:27     ` ron minnich
                         ` (2 preceding siblings ...)
  2008-02-10  8:04       ` maht
@ 2008-02-11 16:39       ` john
  3 siblings, 0 replies; 37+ messages in thread
From: john @ 2008-02-11 16:39 UTC (permalink / raw)
  To: 9fans

> On Feb 9, 2008 8:17 AM, Brantley Coile <brantley@coraid.com> wrote:
>> I would like to hear what Rob or others have to say about the
>> assembler syntax, but I actually like the syntax for the following
>> reason.
>
> if you love assembly code, the assembler on Plan 9 is not great.
>
> If you love assembly code, you are in need of a CAT scan in my view.
>
> The v6 manual entry for as called assembly code "the ultimate dead
> language". If only that had been true.
>
> gcc and friends have made the world safe for assembly, and there is more
> assembly in use than ever.
>
> Writing assembly code should be as painful as possible. Plan 9
> succeeds in that regard. It's a good thing in my view.
>
> ron

And if you can pass off the assembly writing task to an intern, all the
better, right? :)

I don't know... barring certain architecture gotchas, I enjoyed the
assembly I did; it's sort of a relaxing break from C.

John "Real Programmers Use FORTRAN" Floren


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-11  2:39                 ` Pietro Gagliardi
@ 2008-02-11  6:26                   ` maht
  0 siblings, 0 replies; 37+ messages in thread
From: maht @ 2008-02-11  6:26 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Windows 1, 2 &3 was done in assembler


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-11  2:40                 ` Pietro Gagliardi
@ 2008-02-11  2:55                   ` erik quanstrom
  0 siblings, 0 replies; 37+ messages in thread
From: erik quanstrom @ 2008-02-11  2:55 UTC (permalink / raw)
  To: 9fans

> One more thing. Does anyone know if, in raw x86 assembly, RET implies
> STI? Thanks.

if it did, it would be impossible to call a function with interrupts off.

- erik


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-11  2:36               ` Adrian Tritschler
  2008-02-11  2:36                 ` Pietro Gagliardi
  2008-02-11  2:39                 ` Pietro Gagliardi
@ 2008-02-11  2:40                 ` Pietro Gagliardi
  2008-02-11  2:55                   ` erik quanstrom
  2 siblings, 1 reply; 37+ messages in thread
From: Pietro Gagliardi @ 2008-02-11  2:40 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

One more thing. Does anyone know if, in raw x86 assembly, RET implies
STI? Thanks.


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-11  2:36               ` Adrian Tritschler
  2008-02-11  2:36                 ` Pietro Gagliardi
@ 2008-02-11  2:39                 ` Pietro Gagliardi
  2008-02-11  6:26                   ` maht
  2008-02-11  2:40                 ` Pietro Gagliardi
  2 siblings, 1 reply; 37+ messages in thread
From: Pietro Gagliardi @ 2008-02-11  2:39 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Oh, and I can't wait to see those two have GUI support. When I finish
making my OS C- and portability-friendly, I'm going to start with
graphics.

On Feb 10, 2008, at 9:36 PM, Adrian Tritschler wrote:

> Anant Narayanan <anant@kix.in> writes:
>
>>> I am working on rewriting an operating system that avoids this
>>> philosophy for the purpose of teaching assembly language. So far, I
>>> have 2% of the code (I started a rewrite), and I don't know if my
>>> code is 100% right.
>>
>> There's an OS (complete with a Window Manager, IDE, Web Browser, and
>> even some games) written entirely in assembly: http://
>> www.menuetos.net/
>
> Or, if you want something at the other end of the spectrum, there's an
> OS "with modular microkernels using the C# programming language."
>
> http://arstechnica.com/news.ars/post/20080208-developers-create-
> open-source-os-kernels-using-net-tools.html
>
>> Everyone has 24 hours in a day, but some use it more than others ;)
>
> Indeed
>
>> Anant
>   Adrian


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-11  2:36               ` Adrian Tritschler
@ 2008-02-11  2:36                 ` Pietro Gagliardi
  2008-02-11  2:39                 ` Pietro Gagliardi
  2008-02-11  2:40                 ` Pietro Gagliardi
  2 siblings, 0 replies; 37+ messages in thread
From: Pietro Gagliardi @ 2008-02-11  2:36 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 310 bytes --]

On Feb 10, 2008, at 9:36 PM, Adrian Tritschler wrote:

> OS "with modular microkernels using the C# programming language."

Microsoft has too, and it outdates the other two. Unfortunately, it's
only available in Microsoft and a select few universities.

http://research.microsoft.com/os/singularity/


[-- Attachment #2: Type: text/html, Size: 811 bytes --]

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-10 16:55             ` Anant Narayanan
  2008-02-10 18:01               ` erik quanstrom
@ 2008-02-11  2:36               ` Adrian Tritschler
  2008-02-11  2:36                 ` Pietro Gagliardi
                                   ` (2 more replies)
  1 sibling, 3 replies; 37+ messages in thread
From: Adrian Tritschler @ 2008-02-11  2:36 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Anant Narayanan <anant@kix.in> writes:

>> I am working on rewriting an operating system that avoids this
>> philosophy for the purpose of teaching assembly language. So far, I
>> have 2% of the code (I started a rewrite), and I don't know if my
>> code is 100% right.
>
> There's an OS (complete with a Window Manager, IDE, Web Browser, and
>even some games) written entirely in assembly: http://www.menuetos.net/

Or, if you want something at the other end of the spectrum, there's an
OS "with modular microkernels using the C# programming language."

http://arstechnica.com/news.ars/post/20080208-developers-create-open-source-os-kernels-using-net-tools.html

> Everyone has 24 hours in a day, but some use it more than others ;)

Indeed

> Anant
  Adrian


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-10 18:01               ` erik quanstrom
@ 2008-02-10 18:11                 ` Pietro Gagliardi
  0 siblings, 0 replies; 37+ messages in thread
From: Pietro Gagliardi @ 2008-02-10 18:11 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

In C, it could look like

	Write(char *filename, void *data, uvlong number_of_bytes);

so I don't think it has an Open syscall, or probably you read
everything into memory, modify the memory, then write it back. 64-bit
systems can store quite a bit, but this philosophy will get old
almost immediately:

	$ sed2c '1s/^/@/' # given sed2c is a program that converts sed
commands to C
	char *buffer;
	buffer = malloc(FileLen("f"));
	Read("f", buffer, FileLen("f"));
	b[0] = '@';
	Write("f", buffer, strlen(buffer));

Does that seem like a bit much?

On Feb 10, 2008, at 1:01 PM, erik quanstrom wrote:

>> There's an OS (complete with a Window Manager, IDE, Web Browser, and
>> even some games) written entirely in assembly: http://
>> www.menuetos.net/
>>
>> Everyone has 24 hours in a day, but some use it more than others ;)
>>
>
> i can see from their documentation, that i have been using my time
> quite
> a bit more effectively:
>
> 	"Menuet has no roots within UNIX or the POSIX standards,
> 	nor is it based on any particular operating system. The design
> 	goal has been to remove the extra layers between different parts
> 	of an OS, which normally complicate programming and create bugs.
>
> here's their write system call:
>
>               rbx - 1 Write
>
>                 rcx - Ignored
>                 rdx - Bytes to save
>                 rex - Pointer to data
>                 rfx - Filename pointer
>
> !?
>
> - erik


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-10 16:55             ` Anant Narayanan
@ 2008-02-10 18:01               ` erik quanstrom
  2008-02-10 18:11                 ` Pietro Gagliardi
  2008-02-11  2:36               ` Adrian Tritschler
  1 sibling, 1 reply; 37+ messages in thread
From: erik quanstrom @ 2008-02-10 18:01 UTC (permalink / raw)
  To: 9fans

> There's an OS (complete with a Window Manager, IDE, Web Browser, and
> even some games) written entirely in assembly: http://www.menuetos.net/
>
> Everyone has 24 hours in a day, but some use it more than others ;)
>

i can see from their documentation, that i have been using my time quite
a bit more effectively:

	"Menuet has no roots within UNIX or the POSIX standards,
	nor is it based on any particular operating system. The design
	goal has been to remove the extra layers between different parts
	of an OS, which normally complicate programming and create bugs.

here's their write system call:

              rbx - 1 Write

                rcx - Ignored
                rdx - Bytes to save
                rex - Pointer to data
                rfx - Filename pointer

!?

- erik


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-10 14:38           ` Pietro Gagliardi
@ 2008-02-10 16:55             ` Anant Narayanan
  2008-02-10 18:01               ` erik quanstrom
  2008-02-11  2:36               ` Adrian Tritschler
  0 siblings, 2 replies; 37+ messages in thread
From: Anant Narayanan @ 2008-02-10 16:55 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> I am working on rewriting an operating system that avoids this
> philosophy for the purpose of teaching assembly language. So far, I
> have 2% of the code (I started a rewrite), and I don't know if my
> code is 100% right.

There's an OS (complete with a Window Manager, IDE, Web Browser, and
even some games) written entirely in assembly: http://www.menuetos.net/

Everyone has 24 hours in a day, but some use it more than others ;)

--
Anant


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-10  8:56         ` Martin Neubauer
@ 2008-02-10 14:38           ` Pietro Gagliardi
  2008-02-10 16:55             ` Anant Narayanan
  0 siblings, 1 reply; 37+ messages in thread
From: Pietro Gagliardi @ 2008-02-10 14:38 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 409 bytes --]

On Feb 10, 2008, at 3:56 AM, Martin Neubauer wrote:

> (Research) Unix was influential in that
> regard and showed that those parts are really small (and should be).
>
> 	Martin

I am working on rewriting an operating system that avoids this
philosophy for the purpose of teaching assembly language. So far, I
have 2% of the code (I started a rewrite), and I don't know if my
code is 100% right.


[-- Attachment #2: Type: text/html, Size: 1174 bytes --]

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-10  8:18       ` Eris Discordia
@ 2008-02-10  8:56         ` Martin Neubauer
  2008-02-10 14:38           ` Pietro Gagliardi
  0 siblings, 1 reply; 37+ messages in thread
From: Martin Neubauer @ 2008-02-10  8:56 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

* Eris Discordia (eris.discordia@gmail.com) wrote:
> That is probably because assembly was never intended for moving from one
> platform to another all the time, but for squeezing the most out of a
> given platform whose nooks and crannies you ken well.

Nah, that's only what the intel assembler is for. Originally, assembly
language was devised for not having to type in machine opcodes directly.
With the advent of high level programming laguages its main merit became the
ability to write those bits of operating system code that just cannot be
written in a high level language. (Research) Unix was influential in that
regard and showed that those parts are really small (and should be).

	Martin


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-09 17:32     ` Charles Forsyth
@ 2008-02-10  8:18       ` Eris Discordia
  2008-02-10  8:56         ` Martin Neubauer
  0 siblings, 1 reply; 37+ messages in thread
From: Eris Discordia @ 2008-02-10  8:18 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Sat, 09 Feb 2008 17:32:26 -0000, Charles Forsyth
<forsyth@terzarima.net> wrote:

> the assembler is really just a front-end to the loader, and nothing to
> do with `at&t syntax'.

For the first ten minutes after reading that, I was wondering what the
comment meant. Then I remembered in Plan 9 speak the loader means the
linker. So, I gather from what you have pointed out that 8a assembly is
actually some sort of intermediate language like MSIL (or GNU's version of
AT&T assembly for the GCC backend).

> and the <>) but generally i agree with brantley.  some weeks i'm working
> with several processors,
> even several a day, and the `native' (in what sense? does the processor
> implement them?)
> assemblers typically differ in operand order, basic mnemonics (l/st vs
> mov), and other conventions,
> whereas the ?a family is uniformly data flow, and tends to use similar
> instructions for
> similar things.  i find it much easier moving from platform to platform
> with it.

That is probably because assembly was never intended for moving from one
platform to another all the time, but for squeezing the most out of a
given platform whose nooks and crannies you ken well.

The notion of a "native" assembler sounds strange to me. Netwide (nasm) is
known for being available on many software/hardware platforms with similar
syntax (the Intel syntax) all over. Of course, the instruction sets are
far from identical but the syntax is still (almost) the same. Register
access, for instance, is done by simply naming the register in an
instruction:

	mov	eax, 00h

Compared to the AT&T syntax (for GNU assembler):

	movl	$0x0, %eax

(three extra keystrokes to get the same op-code)

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-09 16:27     ` ron minnich
  2008-02-09 16:38       ` erik quanstrom
  2008-02-09 16:51       ` Brantley Coile
@ 2008-02-10  8:04       ` maht
  2008-02-11 16:39       ` john
  3 siblings, 0 replies; 37+ messages in thread
From: maht @ 2008-02-10  8:04 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> If you love assembly code, you are in need of a CAT scan in my view.

chances are the CAT scanner was programmed in assembler !




^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-09 10:32   ` Charles Forsyth
  2008-02-09 10:34     ` erik quanstrom
@ 2008-02-09 20:17     ` Anant Narayanan
  1 sibling, 0 replies; 37+ messages in thread
From: Anant Narayanan @ 2008-02-09 20:17 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> actually, there's probably enough space above your current location
> to (appear to) work, but a further error
> is hinted in the address given by the trap:
>
> 	8.out 1183: suicide: invalid address 0x7 in sys call pc=0x104e
>
> since 7 is your length value, you've also got an off-by-4 error in
> your stack offsets.

In which direction, 4(SP) or -4(SP)?
Both don't work, it still suicides but at different 'invalid
addresses' and pc values :(

--
Anant


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-09 10:34     ` erik quanstrom
  2008-02-09 10:36       ` erik quanstrom
@ 2008-02-09 20:15       ` Anant Narayanan
  1 sibling, 0 replies; 37+ messages in thread
From: Anant Narayanan @ 2008-02-09 20:15 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs


On 09-Feb-08, at 4:04 PM, erik quanstrom wrote:
> actually, i think there's something else wrong:
> for the equivalent c "pwrite(1, string, 7, 0)" i get this

I don't get FP for `8c -S hello.c' (which just calls pwrite as you
describe). This is what I get:

TEXT	main+0(SB), 0, $32
MOVL	$.string<>+0(SB), CX
MOVL	$1, AX
MOVL	AX, (SP)
MOVL	CX, 4(SP)
MOVL	$7, AX
MOVL	AX, 8(SP)
MOVL	$-1, 12(SP)
MOVL	$-1, 16(SP)
CALL	,pwrite+0(SB)
RET ,
DATA	.string<>+0(SB)/8, $"Hello\n\z\z"
GLOBL	.string<>+0(SB), $8
END ,

Replicating the exact program - with just three changes: moving the
DATA/GLOBL statement to the top, changing main to _main and replacing
CALL with MOVL $64, AX and INT $64 - still results in the suicide.

Puzzling.

--
Anant


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-09 16:17   ` Brantley Coile
  2008-02-09 16:27     ` ron minnich
@ 2008-02-09 17:32     ` Charles Forsyth
  2008-02-10  8:18       ` Eris Discordia
  1 sibling, 1 reply; 37+ messages in thread
From: Charles Forsyth @ 2008-02-09 17:32 UTC (permalink / raw)
  To: 9fans

>> No two cents from me. Just posted this to say that AT&T syntax is
>> "sickly." I suppose Anant Narayanan is assembling these using 8a, and
>> given the "symptoms" (the syntax, that is) 8a must be using AT&T syntax. I

the assembler is really just a front-end to the loader, and nothing to do with `at&t syntax'.
there are some odd aspects to thompson syntax as it is (data loading for instance,
and the <>) but generally i agree with brantley.  some weeks i'm working with several processors,
even several a day, and the `native' (in what sense? does the processor implement them?)
assemblers typically differ in operand order, basic mnemonics (l/st vs mov), and other conventions,
whereas the ?a family is uniformly data flow, and tends to use similar instructions for
similar things.  i find it much easier moving from platform to platform with it.


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-09 16:27     ` ron minnich
  2008-02-09 16:38       ` erik quanstrom
@ 2008-02-09 16:51       ` Brantley Coile
  2008-02-10  8:04       ` maht
  2008-02-11 16:39       ` john
  3 siblings, 0 replies; 37+ messages in thread
From: Brantley Coile @ 2008-02-09 16:51 UTC (permalink / raw)
  To: 9fans

> On Feb 9, 2008 8:17 AM, Brantley Coile <brantley@coraid.com> wrote:
>> I would like to hear what Rob or others have to say about the
>> assembler syntax, but I actually like the syntax for the following
>> reason.
>
> if you love assembly code, the assembler on Plan 9 is not great.
>
> If you love assembly code, you are in need of a CAT scan in my view.
>
> The v6 manual entry for as called assembly code "the ultimate dead
> language". If only that had been true.
>
> gcc and friends have made the world safe for assembly, and there is more
> assembly in use than ever.
>
> Writing assembly code should be as painful as possible. Plan 9
> succeeds in that regard. It's a good thing in my view.
>
> ron

I'm afraid Plan 9 fails in this reguard.  Here's some Oberon code
to make the pread call.  (This is NOT Wirth's compiler, but Paul Reed's.
He agrees with you about make assembly programming as hard as possible.)

	PROCEDURE syspread(poshi, poslo: LONGINT;
	    VAR buf: ARRAY OF CHAR; fd: LONGINT): LONGINT;
	BEGIN
		(*
			18: return value
			14: poshi
			10: poslo
			0c: buflen
			08; buf ptr
			04: fd
			00: RA
		*)

		SYSTEM.CODE(
			0C9H,	(* leave *)
			06AH, 50, (* pushb $close *)
			058H, (* pop eax *)
			0CDH, 040H,	(* int $40h *)
			089H,084H,024H,018H,000H,000H,000H,  (* movl eax, 18h(esp) *)
			0C2H, 14H, 0	(* ret $14h *)
		)
	END syspread;



^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-09 16:27     ` ron minnich
@ 2008-02-09 16:38       ` erik quanstrom
  2008-02-09 16:51       ` Brantley Coile
                         ` (2 subsequent siblings)
  3 siblings, 0 replies; 37+ messages in thread
From: erik quanstrom @ 2008-02-09 16:38 UTC (permalink / raw)
  To: 9fans

> if you love assembly code, the assembler on Plan 9 is not great.
> 
> If you love assembly code, you are in need of a CAT scan in my view.
> 
> The v6 manual entry for as called assembly code "the ultimate dead
> language". If only that had been true.
> 
> gcc and friends have made the world safe for assembly, and there is more
> assembly in use than ever.
> 
> Writing assembly code should be as painful as possible. Plan 9
> succeeds in that regard. It's a good thing in my view.
> 
> ron

i don't think that it follows from the fact that assembly language
is inappropriately used in a lot of linux software that it should
be as hard to use as possible on plan 9.

there are some tasks that must be in assembly language.  and it's
a good tool for learning how the machine works.  sometimes, like
on really small controllers, it's the best tool for the job.

just my 2¢.

- erik

p.s. relax ron.  i promise not to rewrite plan 9 in assembly language.


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-09 16:17   ` Brantley Coile
@ 2008-02-09 16:27     ` ron minnich
  2008-02-09 16:38       ` erik quanstrom
                         ` (3 more replies)
  2008-02-09 17:32     ` Charles Forsyth
  1 sibling, 4 replies; 37+ messages in thread
From: ron minnich @ 2008-02-09 16:27 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Feb 9, 2008 8:17 AM, Brantley Coile <brantley@coraid.com> wrote:
> I would like to hear what Rob or others have to say about the
> assembler syntax, but I actually like the syntax for the following
> reason.

if you love assembly code, the assembler on Plan 9 is not great.

If you love assembly code, you are in need of a CAT scan in my view.

The v6 manual entry for as called assembly code "the ultimate dead
language". If only that had been true.

gcc and friends have made the world safe for assembly, and there is more
assembly in use than ever.

Writing assembly code should be as painful as possible. Plan 9
succeeds in that regard. It's a good thing in my view.

ron


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-09 14:37 ` Eris Discordia
@ 2008-02-09 16:17   ` Brantley Coile
  2008-02-09 16:27     ` ron minnich
  2008-02-09 17:32     ` Charles Forsyth
  0 siblings, 2 replies; 37+ messages in thread
From: Brantley Coile @ 2008-02-09 16:17 UTC (permalink / raw)
  To: 9fans

I would like to hear what Rob or others have to say about the
assembler syntax, but I actually like the syntax for the following
reason.  You only have to remember one syntax and not ten different
ones.  I would think, given that the structure of the compiler/loader
is very non-traditional, it would be difficult to provide all the
pseudo operations that the various native assemblers would require.

Best thing is not to write a lot of assembler code. :)




> On Sat, 09 Feb 2008 09:44:21 -0000, Anant Narayanan <anant@kix.in> wrote:
>
>> Hi,
>>
>> I'm trying to make a Hello World program in assembly without depending
>> on libc. Here's what I have so far:
>>
>> DATA	string+0(SB)/7, $"Hello\n\z"
>> GLOBL	string+0(SB), $7
>>
>> TEXT	_main+0(SB), 1, $0
>>
>> // first arg; $1 = stdout
>> MOVL	$1, (SP)
>> // second arg, address of string
>> MOVL	$string+0(SB), 4(SP)
>> // third arg, $7 = length of string
>> MOVL	$7, 8(SP)
>> // fourth argument, -1LL (vlong offset)
>> MOVL	$-1, 12(SP)
>> MOVL	$-1, 16(SP)
>>
>> // use pwrite syscall
>> MOVL	$51, AX
>> INT	$64
>> RET
>>
>
> No two cents from me. Just posted this to say that AT&T syntax is
> "sickly." I suppose Anant Narayanan is assembling these using 8a, and
> given the "symptoms" (the syntax, that is) 8a must be using AT&T syntax. I
> am wondering if there is an Intel syntax assembler for Plan 9 (something
> akin to Netwide Assembler or yet better Flat Assembler).
>
> --
> Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-09  9:44 Anant Narayanan
  2008-02-09  9:58 ` Charles Forsyth
@ 2008-02-09 14:37 ` Eris Discordia
  2008-02-09 16:17   ` Brantley Coile
  1 sibling, 1 reply; 37+ messages in thread
From: Eris Discordia @ 2008-02-09 14:37 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Sat, 09 Feb 2008 09:44:21 -0000, Anant Narayanan <anant@kix.in> wrote:

> Hi,
>
> I'm trying to make a Hello World program in assembly without depending
> on libc. Here's what I have so far:
>
> DATA	string+0(SB)/7, $"Hello\n\z"
> GLOBL	string+0(SB), $7
>
> TEXT	_main+0(SB), 1, $0
>
> // first arg; $1 = stdout
> MOVL	$1, (SP)
> // second arg, address of string
> MOVL	$string+0(SB), 4(SP)
> // third arg, $7 = length of string
> MOVL	$7, 8(SP)
> // fourth argument, -1LL (vlong offset)
> MOVL	$-1, 12(SP)
> MOVL	$-1, 16(SP)
>
> // use pwrite syscall
> MOVL	$51, AX
> INT	$64
> RET
>

No two cents from me. Just posted this to say that AT&T syntax is  
"sickly." I suppose Anant Narayanan is assembling these using 8a, and  
given the "symptoms" (the syntax, that is) 8a must be using AT&T syntax. I  
am wondering if there is an Intel syntax assembler for Plan 9 (something  
akin to Netwide Assembler or yet better Flat Assembler).

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-09 10:34     ` erik quanstrom
@ 2008-02-09 10:36       ` erik quanstrom
  2008-02-09 20:15       ` Anant Narayanan
  1 sibling, 0 replies; 37+ messages in thread
From: erik quanstrom @ 2008-02-09 10:36 UTC (permalink / raw)
  To: 9fans

> acid: asm(_main)
> _main 0x00001020	SUBL	$0x18,SP
> _main+0x3 0x00001023	MOVL	$0x1,0x0(SP)
> _main+0xa 0x0000102a	MOVL	$string(SB),0x4(FP)
> _main+0x12 0x00001032	MOVL	$0x7,0x8(FP)
> _main+0x1a 0x0000103a	MOVL	$0x0,0xc(FP)
> _main+0x22 0x00001042	MOVL	$0x0,0x10(FP)
> _main+0x2a 0x0000104a	MOVL	$0x33,AX
> _main+0x2f 0x0000104f	INTB	$0x40
> _main+0x31 0x00001051	ADDL	$0x18,SP
> _main+0x34 0x00001054	RET
>
> why does the

... SP in the .s get changed to FP unless the offset is 0?

- erik


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-09 10:32   ` Charles Forsyth
@ 2008-02-09 10:34     ` erik quanstrom
  2008-02-09 10:36       ` erik quanstrom
  2008-02-09 20:15       ` Anant Narayanan
  2008-02-09 20:17     ` Anant Narayanan
  1 sibling, 2 replies; 37+ messages in thread
From: erik quanstrom @ 2008-02-09 10:34 UTC (permalink / raw)
  To: 9fans

> actually, there's probably enough space above your current location to (appear to) work, but a further error
> is hinted in the address given by the trap:
>
> 	8.out 1183: suicide: invalid address 0x7 in sys call pc=0x104e
>
> since 7 is your length value, you've also got an off-by-4 error in your stack offsets.

actually, i think there's something else wrong:

acid: asm(_main)
_main 0x00001020	SUBL	$0x18,SP
_main+0x3 0x00001023	MOVL	$0x1,0x0(SP)
_main+0xa 0x0000102a	MOVL	$string(SB),0x4(FP)
_main+0x12 0x00001032	MOVL	$0x7,0x8(FP)
_main+0x1a 0x0000103a	MOVL	$0x0,0xc(FP)
_main+0x22 0x00001042	MOVL	$0x0,0x10(FP)
_main+0x2a 0x0000104a	MOVL	$0x33,AX
_main+0x2f 0x0000104f	INTB	$0x40
_main+0x31 0x00001051	ADDL	$0x18,SP
_main+0x34 0x00001054	RET

why does the
for the equivalent c "pwrite(1, string, 7, 0)" i get this

acid: asm(main)
main 0x00001020	SUBL	$0x18,SP
main+0x3 0x00001023	MOVL	$0x1,AX
main+0x8 0x00001028	MOVL	AX,0x0(SP)
main+0xb 0x0000102b	MOVL	string(SB),AX
main+0x11 0x00001031	MOVL	AX,0x4(SP)
main+0x15 0x00001035	MOVL	$0x7,AX
main+0x1a 0x0000103a	MOVL	AX,0x8(SP)
main+0x1e 0x0000103e	MOVL	$0x0,0xc(SP)
main+0x26 0x00001046	MOVL	$0x0,0x10(SP)
main+0x2e 0x0000104e	CALL	pwrite(SB)
main+0x33 0x00001053	ADDL	$0x18,SP
main+0x36 0x00001056	RET

- erik


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-09  9:58 ` Charles Forsyth
  2008-02-09 10:09   ` Anant Narayanan
@ 2008-02-09 10:32   ` Charles Forsyth
  2008-02-09 10:34     ` erik quanstrom
  2008-02-09 20:17     ` Anant Narayanan
  1 sibling, 2 replies; 37+ messages in thread
From: Charles Forsyth @ 2008-02-09 10:32 UTC (permalink / raw)
  To: 9fans

> there might be more, but you haven't allocated a stack frame for the (system) call

actually, there's probably enough space above your current location to (appear to) work, but a further error
is hinted in the address given by the trap:

	8.out 1183: suicide: invalid address 0x7 in sys call pc=0x104e

since 7 is your length value, you've also got an off-by-4 error in your stack offsets.


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-09 10:09   ` Anant Narayanan
@ 2008-02-09 10:15     ` erik quanstrom
  0 siblings, 0 replies; 37+ messages in thread
From: erik quanstrom @ 2008-02-09 10:15 UTC (permalink / raw)
  To: 9fans

> I did think that was the case earlier, so I tried:
>
> TEXT	_main+0(SB), 1, $32
>
> (And also with values ranging from $4 to $32 in increments of $4 just
> for the heck of it). But it doesn't seem to make any difference in the
> suicide, apart from the changed value of pc.
>
> The error is most likely because of the line (that's the only 7 around
> there):
> MOVL	$7, 8(SP)
>
> But it doesn't complain about:
> MOVL	$1, (SP)
>
> so I wonder...

you seek:
	SUBL	$value, SP

- erik


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-09  9:58 ` Charles Forsyth
@ 2008-02-09 10:09   ` Anant Narayanan
  2008-02-09 10:15     ` erik quanstrom
  2008-02-09 10:32   ` Charles Forsyth
  1 sibling, 1 reply; 37+ messages in thread
From: Anant Narayanan @ 2008-02-09 10:09 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Hi Charles,

> there might be more, but you haven't allocated a stack frame for the
> (system) call

I did think that was the case earlier, so I tried:

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

(And also with values ranging from $4 to $32 in increments of $4 just
for the heck of it). But it doesn't seem to make any difference in the
suicide, apart from the changed value of pc.

The error is most likely because of the line (that's the only 7 around
there):
MOVL	$7, 8(SP)

But it doesn't complain about:
MOVL	$1, (SP)

so I wonder...

--
Anant


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [9fans] Hello Assembly
  2008-02-09  9:44 Anant Narayanan
@ 2008-02-09  9:58 ` Charles Forsyth
  2008-02-09 10:09   ` Anant Narayanan
  2008-02-09 10:32   ` Charles Forsyth
  2008-02-09 14:37 ` Eris Discordia
  1 sibling, 2 replies; 37+ messages in thread
From: Charles Forsyth @ 2008-02-09  9:58 UTC (permalink / raw)
  To: 9fans

> It's probably something silly - I'll be extremely grateful if someone

there might be more, but you haven't allocated a stack frame for the (system) call


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [9fans] Hello Assembly
@ 2008-02-09  9:44 Anant Narayanan
  2008-02-09  9:58 ` Charles Forsyth
  2008-02-09 14:37 ` Eris Discordia
  0 siblings, 2 replies; 37+ messages in thread
From: Anant Narayanan @ 2008-02-09  9:44 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 761 bytes --]

Hi,

I'm trying to make a Hello World program in assembly without depending
on libc. Here's what I have so far:

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

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

// first arg; $1 = stdout
MOVL	$1, (SP)
// second arg, address of string
MOVL	$string+0(SB), 4(SP)
// third arg, $7 = length of string
MOVL	$7, 8(SP)
// fourth argument, -1LL (vlong offset)
MOVL	$-1, 12(SP)
MOVL	$-1, 16(SP)

// use pwrite syscall
MOVL	$51, AX
INT	$64
RET

The program assembles and links fine - but executing it gives me:

8.out 1183: suicide: invalid address 0x7 in sys call pc=0x104e

It's probably something silly - I'll be extremely grateful if someone
could point out what I'm doing wrong.

Thanks!

--
Anant

[-- Attachment #2: Type: text/html, Size: 2181 bytes --]

^ permalink raw reply	[flat|nested] 37+ messages in thread

end of thread, other threads:[~2008-02-11 19:49 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <ead6208b996760a9eb2eeccb8c431b12@plan9.bell-labs.com>
2008-02-09 21:15 ` [9fans] Hello Assembly Anant Narayanan
2008-02-09 21:27   ` Pietro Gagliardi
2008-02-10  8:30     ` Anant Narayanan
2008-02-11 16:36   ` john
2008-02-11 16:43     ` erik quanstrom
2008-02-11 16:45       ` john
2008-02-11 19:41       ` Jon Snader
2008-02-11 19:49         ` Pietro Gagliardi
2008-02-09  9:44 Anant Narayanan
2008-02-09  9:58 ` Charles Forsyth
2008-02-09 10:09   ` Anant Narayanan
2008-02-09 10:15     ` erik quanstrom
2008-02-09 10:32   ` Charles Forsyth
2008-02-09 10:34     ` erik quanstrom
2008-02-09 10:36       ` erik quanstrom
2008-02-09 20:15       ` Anant Narayanan
2008-02-09 20:17     ` Anant Narayanan
2008-02-09 14:37 ` Eris Discordia
2008-02-09 16:17   ` Brantley Coile
2008-02-09 16:27     ` ron minnich
2008-02-09 16:38       ` erik quanstrom
2008-02-09 16:51       ` Brantley Coile
2008-02-10  8:04       ` maht
2008-02-11 16:39       ` john
2008-02-09 17:32     ` Charles Forsyth
2008-02-10  8:18       ` Eris Discordia
2008-02-10  8:56         ` Martin Neubauer
2008-02-10 14:38           ` Pietro Gagliardi
2008-02-10 16:55             ` Anant Narayanan
2008-02-10 18:01               ` erik quanstrom
2008-02-10 18:11                 ` Pietro Gagliardi
2008-02-11  2:36               ` Adrian Tritschler
2008-02-11  2:36                 ` Pietro Gagliardi
2008-02-11  2:39                 ` Pietro Gagliardi
2008-02-11  6:26                   ` maht
2008-02-11  2:40                 ` Pietro Gagliardi
2008-02-11  2:55                   ` erik quanstrom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).