Difference between revisions of "CSC231 Homework 1 2015"
(→Problem 1) |
|||
Line 105: | Line 105: | ||
* Write an assembly language program called '''hw1a.asm''' that displays the following message. | * Write an assembly language program called '''hw1a.asm''' that displays the following message. | ||
* Make the code section (''text section'') of your program contain as few instructions as possible. | * Make the code section (''text section'') of your program contain as few instructions as possible. | ||
+ | <br /> | ||
+ | <code><pre> | ||
================ | ================ | ||
================ | ================ | ||
Line 110: | Line 112: | ||
================ | ================ | ||
================ | ================ | ||
− | + | </pre></code> | |
+ | <br /> | ||
* You will be given on how to submit your program to Moodle in a few days. Stay tuned... | * You will be given on how to submit your program to Moodle in a few days. Stay tuned... | ||
<br /> | <br /> | ||
+ | |||
=Problem 2= | =Problem 2= | ||
<br /> | <br /> |
Revision as of 10:52, 10 September 2015
--D. Thiebaut (talk) 16:08, 8 September 2015 (EDT)
This homework assignment is concurrent with Lecture 1, which took place on 9/9/15. It is due Sunday night 9/20/15, at 11:55 p.m. It is fully understood that we haven't had a chance to fully dig into assembly and understand what instructions do, and how they work. What is asked of you today is simply to use the typical hello world! program in assembly, and modify it in various ways to get it to print a particular message. You are asked to use your programmer's logic in figuring out how to modify a program rather than creating a new one from scratch.
Preparation
Part 1
- Login to your 231a-xx account on aurora.smith.edu.
- Create the following assembly program, assemble it, link it, and run it (the commands are in the header):
;;; ; hw1prep1.asm ;;; ; D. Thiebaut ;;; ; ;;; ; ;;; ; To assemble, link, and run: ;;; ; nasm -f elf hw1prep1.asm ;;; ; ld -melf_i386 -o hw1prep1 hw1prep1.o ;;; ; ./hw1prep1 ;;; ; section .data msg1 db "The quick red fox jumped over the dog", 10 msg1Len equ $-msg1 section .text global _start _start: ;;; print message mov eax, 4 ; write mov ebx, 1 ; stdout mov ecx, msg1 ; address of message to print mov edx, msg1Len ; # of chars to print int 0x80 ;;; exit mov ebx, 0 mov eax, 1 int 0x80
- Observe the output.
Part 2
- Same question, but with a different program. Make sure you study the code of both programs and see how they differ. Then see how their output compare.
;;; ; hw1prep2.asm ;;; ; D. Thiebaut ;;; ; ;;; ; ;;; ; To assemble, link, and run: ;;; ; nasm -f elf hw1prep2.asm ;;; ; ld -melf_i386 -o hw1prep2 hw1prep2.o ;;; ; ./hw1prep2 ;;; ; section .data msg1 db "The quick red fox jumped" msg1Len equ $-msg1 msg2 db " over the dog", 10 msg2Len equ $-msg2 section .text global _start _start: ;;; print message, part 1 mov eax, 4 ; write mov ebx, 1 ; stdout mov ecx, msg1 ; address of message to print mov edx, msg1Len ; # of chars to print int 0x80 ; get Linux to print the message ;;; print message, part 2 mov eax, 4 ; write mov ebx, 1 ; stdout mov ecx, msg2 ; address of message to print mov edx, msg2Len ; # of chars to print int 0x80 ; get Linux to print the message ;;; exit mov ebx, 0 mov eax, 1 int 0x80
Problem 1
- Write an assembly language program called hw1a.asm that displays the following message.
- Make the code section (text section) of your program contain as few instructions as possible.
================
================
= CSC231 FALL 2015 =
================
================
- You will be given on how to submit your program to Moodle in a few days. Stay tuned...
Problem 2
- Same question as for Problem 1, but this time using as few characters in the data section, as possible. You are not limited for the size of your code section any longer. Just the size of the data section should be as small as possible.
Call your program hw1b.py.