The following guidelines are expected for all homework submissions:
all over the mapon my computer or printer. USE SPACES INSTEAD. You can set up almost every modern text editor to insert spaces whenever you press the TAB key, or you can simply pound the spacebar.
pair programmingwhich is part of the Extreme Programming [Agile] software development method. Feel free to collaborate in your pairs as much as you want, doing the entire assignment together. Only submit ONE copy for the both of you.
Cprograms; 3) Verifying the development environment is set up and is functional for assembling
nasmprograms; 4) Verifying that the instructor can access the GitHub repository to provide feedback evaluations during the semester
This homework assignment simply extends the in-class assignment for week one. In classwork01
you
set up and compiled a simple C
program to make sure it worked. This proved the gcc
compiler and linker is working on your computer. It also makes sure your editor is working properly so
that you can create source code with it. These are basic steps, but I want to make sure everyone is on
equal footing from the start of the semester.
The second part of this homework is to verify that your nasm assembler is working properly, which is also
part of the classwork01
exercise.
sayhello.c
program from your week01.html
in class exercise to prompt the user for their name from the terminal command line, using the
printf()
and the gets()
functions. These are also demonstrated in the
F to C
conversion code on the week01.html page. Don't
forget you will need to include BOTH the stdio.h
and stdlib.h
header
files in your source file, just like you need to do in Java using the "import" keyword:
#include <stdio.h> #include <stdlib.h> // main method and code go here...
Hello, World!message to say
Hello,followed by the name that the user has input
dog
, $237.19
, and
just pressing enter
without entering anything. See if you can
break your program and make it crash!sayhello.c
file to your repo under the
classwork/classwork01folder.
dress up your program a bit by making it output some extra blank lines before and after the output. Can you make your program indent the output away from the left margin of the window?
nasm
assembler from
this location using the version
that is appropriate for your operating system. For MacOS, use the macosxversion. You'll need to download the
zipfile and do the installation manually. Once that is done, verify that you can access it from your command line by running the command:
nasm
sayhello.asm
in the same directory where your
sayhello.c
is located.Mac OS version [uses Mac system calls]
global start ; on Linux this should be "_start" section .text start: mov rax, 0x02000004 ; system call for write [Linux should be "_start"] mov rdi, 1 ; file handle 1 is stdout mov rsi, message ; address of string to output mov rdx, 13 ; number of bytes syscall ; invoke operating system to do the write mov rax, 0x02000001 ; system call for exit [Linux use "60"] xor rdi, rdi ; exit code 0 syscall ; invoke operating system to exit section .data message: db "Hello, World", 10
Windows version [usesClibrary's 'printf' function]
global _main ; declares the starting entry point extern _printf ; we'll use the "C" library for now section .text ; code starts here _main: push message ; put the message on the stack call _printf ; call "printf()" to display it add esp, 4 ; set up the exit ret ; return to Windows message: db "Hello, World!", 10, 0
Mac OS version [updated]
nasm -fmacho64 sayhello.asm && ld -macosx_version_min 10.7 sayhello.o -o sayhello2 && ./sayhello2
[NOTE: this is a different command than the original, using thelinkerinstead ofgcc] you can also use semicolons to separate commands:
nasm -fmacho64 sayhello.asm;ld -macosx_version_min 10.7 sayhello.o -o sayhello2;./sayhello2 note the semicolons ↑ ↑
Windows version
nasm -fwin32 sayhello.asm && gcc sayhello.obj -o sayhello2.exe && sayhello2
./sayhello
and on Windows
run using sayhello
. If there are errors, do some Internet searching to see if
you can track down what's going on. If you can't get some help from your friendly prof or a TA from
the Keck Lab in Discord.Cand nasm versions working, see if you can figure out how to do the same
dressing upof your assembler code, putting extra blank lines before and after the text output. Feel free to search the Internet for help. [Hint: check the
messagelabel in the code for clues!]