CISS-150 Project 5 (10 points)
(Updated October 13, 2024)
Overview
Use Linux syscalls to simulate Java method calls like Scanner’s nextLine()
method and PrintWriter’s printf()
method. (similar to fgets()
and printf()
in C).
Learning Outcomes
- Understanding basic assembly instructions.
- Understanding the connection of privileged calls and the Linux OS.
- Understanding the basics of syscalls.
Getting Started
Begin by reviewing Assembly Language with NASM document.
This project continues with the examination of assembly language on the Ubuntu platform.
You will use two additional system calls in Linux to create a basic yet rudimentary interactive program. Since I/O operations are privileged, system calls (syscall) must be utilized for the OS to perform the privileged work on our behalf.
You will learn the complexity of harnessing the CPU in its most primitive form. This exercise uses the x86-64 call model and Linux system calls to move data around. There is much to learn about operating at this level – it is impossible to learn everything at this stage. The goal here is simply exposure to system calls and how some languages, like C, get translated to this code level.
The Code
Again, we are working in a terminal window and must move to the asm
directory.
student@student-vm:~$ cd asm
Then, we will create a new shell program to build the project.
nasm -felf64 -g project5.asm && {
ld project5.o -o project5
chmod +x project5
./project5
}
Like Project 4, this script will build your program, link the pieces, and execute it. After creating that file, you need to change the permissions on it.
student@student-vm:~/asm$ chmod +x project5.sh
Here is a starting point for project 5.
section .bss
name: resb 32 ; 32 bytes for name
section .data
; YOUR PROMPTS AND LENGTHS HERE
section .text
global _start
_start:
;
; YOUR CODE HERE!
;
exit:
mov rax, 60 ; exit
mov rdi, 0 ; return code
syscall
What you need to do next
Your program will prompt the user for their name and then say hello to them using their name.
student@student-vm:~/asm$ ./project5.sh
For example, the output might look like:
Enter your name: Bill Jojo Hello, Bill Jojo
The bold text was entered by the user.
Unlike the previous project, you will not have a library of routines to call upon for the printing and reading. You are manufacturing the complete setup and syscall.
After you complete the reading, remember that `.bss` is for your variables that will receive data and `.data` is for fixed information, like prompts.
The idea is to have fun with the assignment and experiment! Be sure to read up on how additional registers are utilized.
You can see an example starting point below.
section .data
hello: db "Hello, World!",0xa
len: equ $ - hello
section .text
global _start
_start:
mov rax, 1 ; write syscall
mov rdi, 1 ; stdout
mov rsi, hello ; text
mov rdx, len ; length
syscall
exit:
mov rax, 60 ; exit
mov rdi, 0 ; return code
syscall
Glossary of Assembly Language
db - Reserves declared byte space within the program. equ - equate the name on the left with the expression on the right. resb - reserve bytes, the value specifies the number of bytes to be reserved.
Submit a note in the Learning Management System when the project is completed.