A First Assembly Program
Objectives
We would like to :- Code, assemble, and execute a first program in x86 assembly
- Make sure all students present understand how to use the tools/systems required to perform this task.
Notes
- This is all me.
- This is to understand the process
- And a little assembly language.
- We will review the technical details of the code later in much more detail
- What you should already know/learn quickly
- How to log into prog1 or devweb1
- If you don't know this, ask for help
- How to edit/transfer files on these machines
- Probably visual studio code
- I will use vi
- I will use sftp/winscp/wget
- How to use a command line on these machines
- Again, vsc will do this
- I will use putty
- Basic *nix usage
- Use my actions in class for an example
- rm, cp, mv
- mkdir, cd
- ls, pwd
- more/less cat
- io redirection, pipes
- We will discuss a few others at least
- nasm, ld, g++
- gdb
- make
- You will probably want to use make
- It is the right tool for the job.
- I don't care
- Ask about things you do not know.
- Use my actions in class for an example
- How to log into prog1 or devweb1
- Log into prog1 or devweb1 (I prefer prog1)
- I would make an assembly directiry and a prog1 directory inside of that.
- mkdir assembly
- cd assembly
- pwd
- mkdir program1
- cd program1
- pwd
- the pwd is, of course, optional.
- Next download the starting files
- These are optional
- And we might change/remove some of these in the future.
- But for now, PLEASE JUST USE THEM.
- I will use wget
- This is ideal for a remote shell accessing files on the web (web not generic internet)
- Given a URL, this will fetch the file pointed to.
- Apparently this is linux/unix
- But curl is available on windows.
- Or just right click and save in the browser.
- wget https://mirkwood.cs.edinboro.edu/~bennett/class/cmsc3100/spring2026/notes/intro/code/Makefile
- Note, right click in a putty terminal pastes.
- I have no idea how to paste in VSC, but I bet it is right click paste
- Don't copy these from the notes, type wget and copy and paste the first url from the source code page.
- Then use the up arrow and modify the command line for the followign:
- wget https://mirkwood.cs.edinboro.edu/~bennett/class/cmsc3100/spring2026/notes/intro/code/ioCalls.asm
- wget https://mirkwood.cs.edinboro.edu/~bennett/class/cmsc3100/spring2026/notes/intro/code/shell.asm
- wget https://mirkwood.cs.edinboro.edu/~bennett/class/cmsc3100/spring2026/notes/intro/code/CONSTANTS.h
- an ls is probably useful to see if you got the files.
- wget https://mirkwood.cs.edinboro.edu/~bennett/class/cmsc3100/spring2026/notes/intro/code/shell.asm
- We want to make a copy of shell.asm
-
shell.asmis just a starting point to reduce typing. - We want to write Hello World, so let's copy this to hello.asm
- cp shell.asm hello.asm
- You could also do mv shell.asm hello.asm, what is the difference?
-
- Edit hello.asm
- Add the following lines to the data section:
-
section .data GREETING: db 'Hello World!',0 GREETING_FORMAT: db `%s\n`,0 - Note, the second line needs the back quotes ` (upper left hand corner of most keyboards), ' and " will not work.
- Add the following lines to main
-
main: ;mov rdi, format1 ;mov rsi, -1 ;call CallPrintf mov rdi, GREETING_FORMAT mov rsi, GREETING call CallPrintf - Again, we will discuss this in much more detail later.
- But for your homework
-
dbmeans a collection of bytes. -
``is used for strings with escaped characters (\n) -
""and''works for code without escaped characters. - Strings must end with the null terminator (0)
-
- We need to modify the Makefile to assemble and link this new program.
- In your editor, change every reference to
helloWorldto behello
- In your editor, change every reference to
- Assembly and link your program
- make
- Run your program
- ./hello