Difference between revisions of "CSC231 Homework 1 2017"
(→Problem 2: Programming Assignment) |
|||
Line 147: | Line 147: | ||
Also, make sure you do not make any changes to the data section: this means no new string, no new labels, no new constants! The autograder on Moodle will compare the data section of your program to the that of the solution program, and if they are different, you will not be given credit for your program, even if it outputs the correct strings! | Also, make sure you do not make any changes to the data section: this means no new string, no new labels, no new constants! The autograder on Moodle will compare the data section of your program to the that of the solution program, and if they are different, you will not be given credit for your program, even if it outputs the correct strings! | ||
− | |||
− | |||
<br /> | <br /> | ||
+ | ==Documentation== | ||
+ | <br /> | ||
+ | Document your code well. Use programs distributed or made available on the class schedule page as examples of what you should emulate. You do not need to document each instruction, but you should document each group of instructions with a header indicating what the block's function is. | ||
+ | <br /> | ||
+ | ==Submission== | ||
+ | <br /> | ||
+ | Submit your program on '''Moodle'''. Exceptionally, you will be allowed to '''evaluate''' your program with the auto-grader, a feature | ||
+ | that will not be available in the future. This will give you a sense of how the auto-grader parses and evaluates your code. | ||
<br /> | <br /> | ||
Revision as of 09:10, 19 September 2017
--D. Thiebaut (talk) 17:42, 16 September 2017 (EDT)
This assignment is due on Monday Sept. 25, at 11:55 p.m. You can work in pairs on this assignment, in which case you should include both names in the header of the assembly program you will submit for Problem 2.
Contents
Problem #1
Connect to your 231 account, and create this short assembly program, which you can call play1.asm:
;;; ; play1.asm ;;; ; program for Homework 1 ;;; ; ------------------------------------------------------------------- ;;; ------------------------------------------------------------ ;;; data areas ;;; ------------------------------------------------------------ section .data msg1 db "Homework 1", 10 msgLen equ $-msg1 ;;; ------------------------------------------------------------ ;;; code area ;;; ------------------------------------------------------------ section .text global _start _start: mov eax, 4 mov ebx, 1 mov ecx, msg1 mov edx, msgLen int 0x80 ;;; exit() mov eax,1 mov ebx,0 int 0x80 ; final system call
- Assemble, link and run the program. Verify that prints what it should be printing.
- Generate a listing file, by using the -l (minus ell)
nasm -f elf -l play1.lst play1.asm
- Edit the play1.lst file with emacs, and observe the relationship between the opcodes on the left and the corresponding instructions on the right.
- Go back to the play1.asm and change the mov ecx, msg1 line to mov ecx, msg1+4, and change the mov edx, msgLen to mov edx, 5.
- Assemble, link and run the program. Notice that the output is now different.
- Generate a new listing file for the new play1.asm, and see how the opcodes of the two instructions you changed are now different. Make sure you understand how the opcodes relate to the instructions.
Your Assignment
Recreate the assembly program whose opcodes are shown below. I have removed the actual assembly part to leave only the opcodes.
1 2 00000000 486F6D65776F726B20- 3 00000009 616E642043686F636F- 4 00000012 6C61746520646F206E- 5 0000001B 6F206D69782077656C- 6 00000024 6C210A 7 8 9 10 11 12 13 14 15 16 00000000 B804000000 17 00000005 BB01000000 18 0000000A B9[0D000000] 19 0000000F BA09000000 20 00000014 CD80 21 22 00000016 B804000000 23 0000001B BB01000000 24 00000020 B9[26000000] 25 00000025 BA01000000 26 0000002A CD80 27 28 0000002C B801000000 29 00000031 BB00000000 30 00000036 CD80
- Question
- What is the output of this mystery program? Please answer this question on Moodle. You do not need to submit the program you created. You only need to figure out what it prints.
Problem 2: Programming Assignment
You are given a program that is missing its code section. Reconstruct the code section without modifying the data section, so that the output of the program is the following:
cs231a-xx@aurora ~ $ ./hw1 ------------------------------------ --------- CSC231 Assembly ---------- ------------------------------------ cs231a-xx@aurora ~ $
The incomplete source code of your program is given below:
;;; hw1.asm ;;; Your name ;;; ;;; Add a description here ;;; ;;; To assemble, link, and run: ;;; nasm -f elf hw1.asm ;;; ld -melf_i386 -o hw1 hw1.o ;;; ./hw1 ;;; section .data ;;; you are not allowed to make any changes to the data section ;;; below. msg db " CSC231 Assembly " linefeed db 10 dashline db "------------------" lineLen equ $-dashline section .text global _start _start: ;;; put your code below this point ;;; exit. Do not add code below this line. mov ebx, 0 mov eax, 1 int 0x80
Call your program hw1.asm and submit it to the programming section of Homework 1 on Moodle when you are done.
Make sure the output of your program matches the output shown above, EXACTLY!
Also, make sure you do not make any changes to the data section: this means no new string, no new labels, no new constants! The autograder on Moodle will compare the data section of your program to the that of the solution program, and if they are different, you will not be given credit for your program, even if it outputs the correct strings!
Documentation
Document your code well. Use programs distributed or made available on the class schedule page as examples of what you should emulate. You do not need to document each instruction, but you should document each group of instructions with a header indicating what the block's function is.
Submission
Submit your program on Moodle. Exceptionally, you will be allowed to evaluate your program with the auto-grader, a feature
that will not be available in the future. This will give you a sense of how the auto-grader parses and evaluates your code.
Problem 3
Assume that you connect to your cs231a-xx account and type the following commands:
cd mkdir temp1 mkdir temp1/temp2 cd temp1/temp2 mkdir temp3 mkdir temp4 cd temp4 mkdir temp5 mkdir temp5/temp6 cd temp5 cd temp6 emacs myprog.asm cd
Go to Moodle, and locate this problem as the "Bash Problem", and in the series of Linux commands listed there, identify the one group that would correctly display the contents of the myprog.asm file?