Assembly

Jerry Feldman gaf at blu.org
Sat Jan 29 10:55:01 EST 2000


It is the GNU as assembler, which should be installed as the as command. 
All the docs are online in info format if you installed them.
One of the things I generally do as an assembly language programmer is to 
cheat by prototyping my task in C, and letting the compiler generate the 
assembly. Then I hand tune the assembly code to do exactly what I want. I'm 
much more lamiliar with the Alpha assembly language than with the Intel. 
There are some things you need to be aware of when you write assembly on 
most platforms:
1. calling standards so you can call and be called by other languages. 
2. Assembler directives. These tell the assmbler things like controlling 
the
   listing, scoping of varibles and functions. even the type of function. 
   Some of the directives, such as .ent and .prolog are used to build a  
   procedure descriptor, which is used by debuggers, linkers and 
optimizers.
   I'll annotate below in alpha assembler.

Here is an example (in alpha assembler):
Hello workd in C:
#include <stdio.h>
int main()
{
        printf("Hello, world\n");
        return 0;
}
In assember:
        .file   1 "hw.c"
        .set noat		#tells assembler not to use register AT
        .set noreorder		#tells assembler not so optimize
.section        .rodata		#declares section for read/only data
$LC0:
        .ascii "Hello, world\n\0"	# declares an ASCII string.
					# The .asciiz directive produces a
					# null terminated line.
.text				#declares section text.
        .align 5		#sets alignment to 32 byte boundary
				# the 5 is the number of zero bits. 
				# in alpha assembler.
        .globl main		# exports symbol main.
        .ent main		# this sets up the procedure descriptor, 
				# which tells the linker that this is a 
				# function.
main:
        .frame $15,16,$26,0	# just establishes the stack frame
        .mask 0x4008000,-16
        ldgp $29,0($27)		# loads the gp register. In the alpha
				# the gp register is essentially a base
				# register.
$main..ng:
        subq $30,16,$30		#$30 is the stack pointer in Linux alpha
        stq $26,0($30)		#stores register 26 (return value) in the 
				# stack frame.
        stq $15,8($30)		# Register 15 is the first parameter. 
        bis $30,$30,$15		# copy stack pointer to reg 15 
				# (15=frame pointer)
        .prologue 1		# end of prolog, beginning of procedure 
        lda $16,$LC0		# Load address of "Hello, World" as
				# parameter 1 (alpha uses registers
				# as parameters. 
        jsr $26,printf		#
        ldgp $29,0($26)		# Reset gp(Note that reg 26 is the 
				# return address.
        bis $31,$31,$0		# Copy register 31 (always zero) to 
				# return value register. 		
        br $31,$L1		# stupid branch to epilog
$L1:
        bis $15,$15,$30		# Reset old stack pointer.
        ldq $26,0($30)		# Retrieve return address.
        ldq $15,8($30)		# Retrieve caller's frame pointer
        addq $30,16,$30		# Adjust stack pointer to value as called.
        ret $31,($26),1		# return to caller
        .end main
        .ident  "GCC: (GNU) egcs-2.91.66 19990314/Linux (egcs-1.1.2 
release)"


"Anthony J. Gabrielson" wrote:
> Hello,
> 	I have two questions.  First can anybody tell me about the Linux
> assembler, I think its called gas - but not sure.  Second does anyone know
> where I can find all the interrupt functions listed?  I am getting into
> assembley and need a few pointers so as always any help is appreciated.
-- 
Jerry Feldman <gaf at blu.org>
Boston Linux and Unix user group
http://www.blu.org


-
Subcription/unsubscription/info requests: send e-mail with
"subscribe", "unsubscribe", or "info" on the first line of the
message body to discuss-request at blu.org (Subject line is ignored).



More information about the Discuss mailing list