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. Agile teams are prevalent in the industry now, so feel free to collaborate in your groups as much as you want, doing the entire assignment together. Only submit ONE copy for the group.
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 classwork01
in class exercise so that it prompts the user for their name from the terminal command line, using
the printf()
and the fgets()
or scanf()
functions. These are
also demonstrated in the F to C
conversion code on the week01
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 or Python using the importkeyword:
#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 typed in
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
homework/homework01folder.
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?- Commit all your code so far to your repo to make sure you've captured your properly working code.
nasm
assembler from
this location using the version
that is appropriate for your operating system. For MacOS, use the macosxversion, and you will need to download the
zipfile and do the installation manually. You will download a
zip
file. It is recommended that you move that file into a different directory,
and NOT install nasm
into your Downloads directory. You will need
to add the installation directory into your PATH so that the O/S can find it.win64version, and download the
.exe
file, which is a self-extracting zip file; this will also run the installation
process and [I think] add the installation directory to your search path.nasm
nasm
is properly installed you should see an error message saying that you didn't
provide a source file for nasm to work on.
as
assembler and the ld
loader to
create your programs. These tools are already installed with the new MacOS versions. You can
check this by running the following commands:as filename.arm ld filename
sayhello.nasm
in the same directory where your
sayhello.c
is located. For M-level Mac
name the file
sayhello.arm
.
X86-64 Mac OS version [uses Mac X86-64 system calls]
global start ; defines the program entry point 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
M-level Mac version [uses Mac M-level system calls]
.global _main ; declares the starting entry point .aligh 2 _main: mov X0, #1 ; 1 = stdout, the display adr X1, message ; address of start of message mov X2, #13 ; length of output string mov X16, #4 ; "4" is write system function svc 0 ; call the system _exit: mov X0, #0 ; returns zero to O/S mov X16, #1 ; exit system function svc 0 ; call the system message: .ascii "Hello, World!\n"
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 X86-64 version
nasm -fmacho64 sayhello.nasm ld -macosx_version_min 13.0.0 sayhello.o -o sayhello ./sayhello
Mac OS M-level version
as -o sayhello.o sayhello.arm ld -macosx_version_min 13.0.0 -o sayhello sayhello.o -lSystem -syslibroot `xcrun sdk macosx --show_sdk_path` -e start -arch arm64 ./sayhello
Windows version
nasm -fwin32 sayhello.asm gcc sayhello.obj -o sayhello.exe sayhello
./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!]