Difference between revisions of "CSC231 Crash Course Solution 6"
(Created page with "--~~~~ ---- <code><pre> </pre></code> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> Category:CSC231") |
|||
Line 2: | Line 2: | ||
---- | ---- | ||
<code><pre> | <code><pre> | ||
+ | ;;; prog6.asm | ||
+ | ;;; D. Thiebaut | ||
+ | ;;; solution for Exercise #6 | ||
+ | ;;; | ||
+ | ;;; Assemble, link and run as follows: | ||
+ | ;;; nasm -f elf asm_io.asm (do this only once) | ||
+ | ;;; nasm -f elf prog6.asm | ||
+ | ;;; gcc -o prog6 driver.c prog6.o asm_io.o | ||
+ | ;;; ./prog6 | ||
+ | ;;; | ||
+ | %include "asm_io.inc" | ||
+ | |||
+ | %assign SYS_EXIT 1 | ||
+ | |||
+ | ;; ------------------------- | ||
+ | ;; data segment | ||
+ | ;; ------------------------- | ||
+ | section .data | ||
+ | table dd 0, 1, 0, 10, 11, 4, 0, 0, 100, 0 | ||
+ | |||
+ | ;; ------------------------- | ||
+ | ;; code area | ||
+ | ;; ------------------------- | ||
+ | section .text | ||
+ | global asm_main | ||
+ | asm_main: | ||
+ | mov ecx, 10 ; get ready to loop 10 times | ||
+ | mov esi, table ; make esi point to a | ||
+ | |||
+ | for: mov eax, [esi] | ||
+ | cmp eax, 0 | ||
+ | je done | ||
+ | call print_int | ||
+ | call print_nl | ||
+ | done: add esi, 4 | ||
+ | loop for | ||
+ | |||
+ | ;; return to C program | ||
+ | |||
+ | ret | ||
</pre></code> | </pre></code> |
Latest revision as of 15:12, 4 March 2011
--D. Thiebaut 15:10, 4 March 2011 (EST)
;;; prog6.asm
;;; D. Thiebaut
;;; solution for Exercise #6
;;;
;;; Assemble, link and run as follows:
;;; nasm -f elf asm_io.asm (do this only once)
;;; nasm -f elf prog6.asm
;;; gcc -o prog6 driver.c prog6.o asm_io.o
;;; ./prog6
;;;
%include "asm_io.inc"
%assign SYS_EXIT 1
;; -------------------------
;; data segment
;; -------------------------
section .data
table dd 0, 1, 0, 10, 11, 4, 0, 0, 100, 0
;; -------------------------
;; code area
;; -------------------------
section .text
global asm_main
asm_main:
mov ecx, 10 ; get ready to loop 10 times
mov esi, table ; make esi point to a
for: mov eax, [esi]
cmp eax, 0
je done
call print_int
call print_nl
done: add esi, 4
loop for
;; return to C program
ret