Minix assembly pseudo-ops, sections, and comments

modified: 12 Mar 2003

Kees Bot answers more questions about Minix assembly language:

Q: What do the pseudo-ops in Minix assembly code mean?

A: An ACK assembly file can have a number of sections. Things declared in the same section are collected together by the loader in the order they are found in an assembly file and in the order the object files are loaded together.

Sections get meaning once they are put in a Minix binary. Section 0 (usually named .text) contains program code and is put in the code segment, section 1 (.rom) is read-only data and is put in the data segment, and so are section 2 (.data) for read-write data and section 3 (.bss) for read-write data initialized to zero.

The ACK binary to Minix binary converter (cv) will complain if there are nonzero objects in the .bss section, but it doesn't care if there's code in .rom/.data, or data in .text.

With .define a label is turned into a global variable that other files can use, otherwise it stays local to the assembly file it is in. With .extern one can import a global label, but the assembler seems to do that automatically anyway.

With .comm you can put a label on a bunch of zeros. This is useful in the .bss section. I haven't found a difference between ".comm junk, 10" and "junk: .space 100".

With .align you can insert the number of zeros needed to align '.' (the address where stuff is put) to a given multiple. Objects bigger than a byte should be aligned to multiples of 2 or 4 bytes. Otherwise it will be slow on 386 descendants, cause alignment fault messages under Minix-vmd on a 486+, and crash horribly on processors other than the 386.

With .data[124] you can assemble 1, 2 or 4 byte sized numbers. With '.ascii "xyz"', and '.asciz "xyz"' you can do the same as with .data1 120, 121, 122 and .data1 120, 121, 122, 0.

Q: At the beginning of the code there is a line: ".sect .text; .sect .rom; .sect .data; .sect .bss". Or there is ".sect .text begtext:". What do these mean? In the code ".sect .text" shows up again. What does this mean? What is the explanation of the segments in Minix assembly code?

A: A new section name opens up a new section. By naming all sections in the first line you can be sure that the names are tied to the proper section numbers.

Q: About comments, I guess '!' begins a comment that extends to the end of the line, is that right? And I see C-style "/*...*/" comments in macros in .s files. Can these only be used in macros? Can "#include" and "#define" be used in .s files, and do they work as in .c files?

A: The comment character is '!'. The C preprocessor is run on an assembly file if the very first character is a '#'. If so then the "/*... */" comment characters also work, because the C preprocessor removes C comments. The quote characters (', ") are a bit of a problem, because the preprocessor wants them to match. This is why you see '`' (backquote) used in comments sometimes where one would normally use a ''' (single quote).

I've more or less figured this out on my own with no more information than the rest of you have. When I found a few meagre manual pages on this in the ACK tree they told me nothing more than I had already figured out myself. What helps are good Intel manuals (I got the Pentium Pro set), a bit of imagination on how the ACK assembler would encode the instructions and then simply trying.

Kees J. Bot, Systems Programmer, Sciences dept., Vrije Universiteit Amsterdam

Credits: This is slightly edited from an article posted to comp.os.minix:

From: kjb=733167@cs.vu.nl (Kees J Bot)
Newsgroups: comp.os.minix
Subject: Re: assemble in Minix
Date: Tue, 11 Mar 2003 15:02:29 +0100


Mail comments on this page to: Al Woodhull <awoodhull@hampshire.edu>
created by mkhtml: Jan 1 20:10