To practice writing and running basic x86 assembly code, using the Jasmin interpreter.
Open a Web browser and go to
Click the "Do I have Java?" link. Follow the instructions on your screen to download and run a Java applet. If you don't have Java, download and install it.
Note: If you are using the Mac, you should use Safari, not Chrome.
In a Web browser, download this file:
Double-click the Jasmin-1.5.8-PC.jar file you downloaded. Jasmin launches.
Click the "New File" button. Look over the window, referring to the diagram below:
Find and examine these sections:
The ESP (Extended Stack Pointer) contains the address of the top of the Stack.
The EIP (Extended Instruction Pointer) contains the address of the the next instruction to be processed.
With the Memory pane scrolled to the top, as shown in the image above, you see memory that the program will use to store data during processing.
Scroll this pane to the bottom to see the Stack, which starts at address 0x1000 and grows downward.
In the Code section, type in these instructions.
mov eax, 4 mov ebx, 6These instructions move the number 4 into eax, and the number 6 into ebx.
At the top of the Jasmin window, click the green Run button, as shown below.
The program runs. When it stops, notice these things, as shown below:
Troubleshooting
If you make an error in an instruction, the program will stop prematurely. Fix the instruction, and click the Reset button. Then you can run it again.
Add more lines to your Code section to make your program look like this:
mov eax, 4 mov ebx, 6 mov [eax], ebx mov ecx, eax add ecx, ebx mov [eax+4], ecxHere's what these instructions do:
mov eax, 4 |
Move the value 4 into eax |
mov ebx, 6 |
Move the value 6 into ebx |
mov [eax], ebx |
Move the value in ebx (which is 6) into the memory location pointed to by eax (memory location 4) |
mov ecx, eax |
Move the value in eax (which is 4) into ecx |
add ecx, ebx |
Add the value in ebx (which is 6) to the value in ecx (which is 4), and put the result into ecx (the result is 10) |
mov [eax+4], ecx |
Move the value in ecx (which is 10) into the memory location four past the location pointed to by eax (memory location 8) |
In Jasmin, click File, New.
In the Code section, type in these instructions.
mov eax, 4 mov ebx, 6 push eax push ebx
Before running the program, notice the ESP: it contains 256, as shown below
.256 is 0x100 in hexadecimal--this is where the Stack ends.
Scroll down in the Memory pane to see the last values. As show below, the last location is at 0xFC. This value is 32 bits long, so it contains four bytes, at locations 0xFC, 0xFD, 0xFE, and 0xFF. The ESP points to the next byte, 0x100.
These instructions move the number 4 into eax, and the number 6 into ebx. Then both values are pushed onto the stack.
Notice these things, as shown below:
mov eax, 4 mov ebx, 6 push eax push ebx pop ecxRun the code.
Notice these things, as shown below:
In Jasmin, click File, New.
In the Code section, type in these instructions.
mov eax, 1 mov ebx, 2 mov ecx, 3 mov edx, 4 push eax push ebx push ecx push edx pop eax pop ebx pop ecx pop edx
These instructions load values into the four registers, push them onto the stack in order, and pop them off the stack in order
.However, since the stack is a FILO (First In, Last Out) structure, this reverses the order of the values.
Push the Step four times to execute only the first four instructions, as shown below:
You see the values 1, 2, 3, and 4 loaded into the EAX, EBX, ECX, and EDX registers, as shown below.
Push the Step four more times to execute only the next four instructions.
You see the values 1, 2, 3, and 4 pushed onto the stack, as shown below.
Push the Step four more times to execute the remaining four instructions.
Now the registers contain these values:
In Jasmin, click File, New.
In the Code section, type in these instructions.
mov eax, 1 mov ebx, 9 mov ecx, 49 push eax push ebx push eax push ecx push ebx push eax pop eax pop ebx pop ecx add eax, ebx pop ecx add eax, ecx pop ebx pop ecx add eax, ebx
Load and run this program. Find the value of eax, which is covered by a green box in the image below. Enter that value into the form below.
Use the form below to record your score in Canvas.