Example Programs
A standard “Hello, world!” program for Linux on IA-32:
.data msg: .asciz "Hello, world!\n" # "asciz" will cause the assembler to append # the null byte that many C library routines # expect. The C library isn't being used in # the example. MSGLEN = . - msg # this will cause the assembler to count the number of bytes # between the label "msg" and here. The number will be 16, # as the null byte is included. .text .globl _start _start: movl $MSGLEN,%edx # argument 3 for write. Number of bytes to write. # A macro is used, which means the MSGLEN will be # replaced with the immediate value 0xf (15) during # assembly. Comparable to C preprocessor macros. movl $msg,%ecx # argument 2 for write. Pointer to data. movl $1,%ebx # argument 1. file descriptor number. (stdout=1, see article on file descriptors) movl $4,%eax # syscall number 4 = write(2) int $0x80 xorl %ebx,%ebx # argument for syscall. exit code = 0 (xor of a value with itself always equals 0) movl $1,%eax # syscall number 1 = exit(2) int $0x80A standard “Hello, world!” program for FreeBSD and Mac OS X on IA-32:
.data msg: .asciz "Hello, world!\n" MSGLEN = . - msg .text .globl _start _start: pushl $MSGLEN pushl $msg pushl $1 movl $4,%eax subl $4,%esp int $0x80 addl $16 pushl $0 movl $1,%eax subl $4,%esp int $0x80Read more about this topic: GNU Assembler
Famous quotes containing the word programs:
“Government ... thought [it] could transform the country through massive national programs, but often the programs did not work. Too often they only made things worse. In our rush to accomplish great deeds quickly, we trampled on sound principles of restraint and endangered the rights of individuals.”
—Gerald R. Ford (b. 1913)
“Whether in the field of health, education or welfare, I have put my emphasis on preventive rather than curative programs and tried to influence our elaborate, costly and ill- co-ordinated welfare organizations in that direction. Unfortunately the momentum of social work is still directed toward compensating the victims of our society for its injustices rather than eliminating those injustices.”
—Agnes E. Meyer (18871970)