Difference between revisions of "CSC231 Loop Exercises"
(→Exercise 3) |
|||
Line 40: | Line 40: | ||
<br /> | <br /> | ||
<br /> | <br /> | ||
+ | <onlydft> | ||
+ | |||
+ | <source lang="asm"> | ||
+ | ;;; printStars.asm | ||
+ | ;;; D. Thiebaut | ||
+ | ;;; | ||
+ | ;;; | ||
+ | ;;; | ||
+ | ;;; To assemble, link, and run: | ||
+ | ;;; nasm -f elf -F stabs printStars.asm | ||
+ | ;;; ld -melf_i386 -o printStars printStars.o | ||
+ | ;;; ./printStars | ||
+ | ;;; | ||
+ | |||
+ | section .data | ||
+ | |||
+ | stars db 0x0a, "******************************" | ||
+ | starsLen equ $-stars | ||
+ | |||
+ | addr dd stars | ||
+ | count dd starsLen | ||
+ | |||
+ | section .text | ||
+ | global _start | ||
+ | _start: | ||
+ | mov ecx, dword[count] | ||
+ | |||
+ | for: mov dword[count], ecx | ||
+ | mov eax, 4 | ||
+ | mov ebx, 1 | ||
+ | mov ecx, stars | ||
+ | mov edx, dword[count] | ||
+ | int 0x80 | ||
+ | |||
+ | mov ecx, dword[count] | ||
+ | loop for | ||
+ | |||
+ | ;;; exit | ||
+ | mov ebx, 0 | ||
+ | mov eax, 1 | ||
+ | int 0x80 | ||
+ | </source> | ||
+ | <br /> | ||
+ | </onlydft> | ||
<br /> | <br /> | ||
[[Category:CSC231]][[Category:Exercises]] | [[Category:CSC231]][[Category:Exercises]] |
Revision as of 08:18, 10 October 2012
--D. Thiebaut 11:21, 20 October 2010 (UTC)
Exercise 1
Review. Write a simple program that prints a line of 30 stars
******************************
Exercise 2
Using a loop, write a simple program that prints 30 lines of stars, such that the first line contains 30 stars, the next one 29 stars, then 28 stars, until the last line printed contains only 1 star.
****************************** ***************************** **************************** *************************** ************************** ************************* ************************ *********************** ********************** ********************* . . . *** ** *
Exercise 3
Same exercise, but this time the first line printed contains 1 star, the next 2 stars, and so on until the last one, which contains 30 stars.