Difference between revisions of "CSC231 Functions and the Stack"
(Created page with "--~~~~ ---- =A Shell File to Assemble and Link= * The text file below can be created with emacs. Call it '''nasmld''' (or some other name of your choosing): <br /> <source lan...") |
(→A Shell File to Assemble and Link) |
||
Line 6: | Line 6: | ||
* The text file below can be created with emacs. Call it '''nasmld''' (or some other name of your choosing): | * The text file below can be created with emacs. Call it '''nasmld''' (or some other name of your choosing): | ||
<br /> | <br /> | ||
− | <source lang=" | + | <source lang="bash"> |
#! /bin/bash | #! /bin/bash | ||
# nasmld | # nasmld | ||
Line 21: | Line 21: | ||
<br /> | <br /> | ||
+ | |||
=Program 1= | =Program 1= | ||
<br /> | <br /> |
Revision as of 09:41, 31 October 2012
--D. Thiebaut 10:41, 31 October 2012 (EDT)
A Shell File to Assemble and Link
- The text file below can be created with emacs. Call it nasmld (or some other name of your choosing):
#! /bin/bash
# nasmld
# a script to assemble and link assembly files
nasm -f elf -F stabs $@.asm
ld -o $@ -melf_i386 $@.o
./$@
- make sure you make your script executable by using this command:
chmod a+rx nasmld
Program 1
;;; ------------------------------------
;;; funcExample.asm
;;; prints 2 strings using functions
;;; ------------------------------------
section .data
Hello db "Hello "
There db "there!", 10, 10, 10
HelloLen equ $-Hello
section .text
global _start
_start:
;;; ------------------------------------
;;; main program
;;; ------------------------------------
;;; print message
mov ecx, Hello
mov edx, HelloLen
call printString
mov ecx, There
mov edx, 9
call printString
;;; exit
mov ebx, 0
mov eax, 1
int 0x80
;;; ------------------------------------
;;; printString: prints string whose
;;; address is in ecx, and length in edx
;;; ------------------------------------
printString:
mov eax, 4
mov ebx, 1
int 0x80
ret
Program 1
;;; ----------------------------------
;;; funcExample2.asm
;;; prints 2 strings with lines of stars
;;; between them
;;; ----------------------------------
section .data
Hello db "Hello "
There db "there!", 10, 10, 10
HelloLen equ $-Hello
line db "****************************", 10
lineLen equ $-line
section .text
global _start
_start:
;;; ----------------------------------
;;; main program
;;; ----------------------------------
call printLine
mov ecx, Hello
mov edx, HelloLen
call printString
call printLine
mov ecx, There
mov edx, 9
call printString
call printLine
;;; exit
mov ebx, 0
mov eax, 1
int 0x80
;;; ----------------------------------
;;; printString: Prints a string whose
;;; address is in ecx and length in edx
;;; ----------------------------------
printString: mov eax, 4
mov ebx, 1
int 0x80
ret
;;; ----------------------------------
;;; printLine: prints a line of stars.
;;; ----------------------------------
printLine: mov ecx, line
mov edx, lineLen
call printString
ret