$30
Lab 2
Submit Assignment
In this lab, we are not going to use GCC, but rather assemble and link our program directly through the assembler (as)
and linker (ld). These are important steps that shouldn't be taken lightly as in later more complicated assignments,
students get confused and frustrated as to why their program won't assemble and/or link.
1. Create a subfolder named Lab2 in your "CS3B" folder.
2. Using LeafPad or similar text editor, type the following instructions.... of course, change the name from Lab0.s to
Lab2.s.
Do not enter the line numbers as they are part of the text editor.
4. Save the file as Lab2.s
5. (Optional): If you don't know how to take a screenshot, go ahead and install scrot i.e.
sudo apt-get install scrot
6. Enter the following commands in a terminal to assemble, link, and execute your program.
as -g -o lab2.o lab2.s
ld -o lab2 lab2.o
./lab2 ; echo $?
as: The GNU “as” (assembler) program reads the assembly language statements in the source text file and writes an
object file containing machine code instructions.
The -g flag is optional at this time as it is meant to allow our debugger (Lab 3) to debug our executable.
ld: The “ld” (linker) program reads the object file, combines it with any needed utilities, and writes the executable file
that is ready to run.
Once you assemble this program using the “as” command, link it using the “ld” command, and execute it with the
“./lab2” command, you can then display its output “status” value of 0 using the “echo $?” command.
1/24/2020 Lab 2
https://canvas.saddleback.edu/courses/34106/assignments/544358?module_item_id=1163333 2/2
*** CORRECTION: replace first with Lab2 in the picture below !!
7. take a screen shot from within the Lab2 directory as shown above and rename it to Lab2.png
8. Upload Lab2.s and Lab2.png to complete this assignment.