ED 304: Using Jasmin to Run x86 Assembly Code (10 pts) ED 304:使用Jasmin运行x86汇编代码(10分)

What You Need for This Project你需要什么这个项目

Purpose目的

To practice writing and running basic x86 assembly code, using the Jasmin interpreter.使用Jasmin解释器练习编写和运行基本的x86汇编代码。

Understanding the Jasmin Window了解Jasmin窗口

You can download the latest version of Jasmin here , but you may prefer the one without the cheesecake image, which is here .你可以在这里下载最新版本的Jasmin,但你可能更喜欢没有芝士蛋糕图像的那个,就在这里

Double-click the Jasmin-1.5.8.jar file you downloaded.双击下载的Jasmin-1.5.8.jar文件。

Jasmin launches, with a cringe-worthy pinup on it. Jasmin推出了一款令人畏缩的贴图。

Click the " New File " button.单击“ 新建文件 ”按钮。

Look over the window, referring to the diagram below:查看窗口,参考下图:

Find and examine these sections:查找并检查以下部分:

Registers寄存器

Data used during processing is stored in the registers EAX , EBX , ECX , and EDX .处理期间使用的数据存储在寄存器EAXEBXECXEDX中

The ESP (Extended Stack Pointer) contains the address of the top of the Stack. ESP (扩展堆栈指针)包含堆栈顶部的地址。

The EIP (Extended Instruction Pointer) contains the address of the the next instruction to be processed. EIP (扩展指令指针)包含要处理的下一条指令的地址。

Flags

These one-bit values that are used for branching.这些一位值用于分支。 For example the JZ instruction will jump if the Zero flag is 1 (set), and the JNZ instruction will jump if the Zero flag is 0 (cleared).例如,如果Zero标志为1(设置),则JZ指令将跳转;如果Zero标志为0(清除),则JNZ指令将跳转。

Code

This is where you type in commands, such as mov eax,4这是您键入命令的位置,例如mov eax,4

Help救命

Help messages appear here.此处显示帮助消息。

Memory记忆

This processor has 0x1000 = 4096 bytes of RAM, which is not enough to run complete modern programs, but plenty for running little assembly programs for learning purposes.这个处理器有0x1000 = 4096字节的RAM,这不足以运行完整的现代程序,但是很多用于运行的小程序集程序用于学习目的。

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.将Memory页面滚动到顶部,如上图所示,您将看到程序在处理过程中用于存储数据的内存。

Scroll this pane to the bottom to see the Stack, which starts at address 0x1000 and grows downward.将此窗格滚动到底部以查看堆栈,堆栈从地址0x1000开始向下增长。

Using mov Instructions使用mov说明

In the Code section, type in these instructions.在“代码”部分中,键入这些说明。
mov eax, 4 mov eax,4
mov ebx, 6 mov ebx,6
These instructions move the number 4 into eax, and the number 6 into ebx.这些指令将数字4移动到eax,将数字6移动到ebx。

At the top of the Jasmin window, click the green Run button, as shown below.在Jasmin窗口的顶部,单击绿色的“运行”按钮,如下所示。

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.然后你可以再次运行它。

Storing Results in Memory将结果存储在内存中

Add more lines to your Code section to make your program look like this:在代码部分添加更多行,使您的程序如下所示:
mov eax, 4 mov eax,4
mov ebx, 6 mov ebx,6
mov [eax], ebx mov [eax],ebx
mov ecx, eax mov ecx,eax
add ecx, ebx添加ecx,ebx
mov [eax+4], ecx mov [eax + 4],ecx
Here's what these instructions do:以下是这些说明的作用:
mov eax, 4 Move the value 4 into eax将值4移动到eax中
mov ebx, 6 Move the value 6 into ebx将值6移动到​​ebx
mov [eax], ebx Move the value in ebx (which is 6) into the memory location pointed to by eax (memory location 4)将ebx(即6)中的值移动到eax指向的内存位置(内存位置4)
mov ecx, eax Move the value in eax (which is 4) into ecx将eax(即4)中的值移动到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)将ebx中的值(即6)添加到ecx中的值(即4),并将结果放入ecx(结果为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)将ecx中的值(即10)移动到eax指向的位置之外的内存位置(内存位置8)
Run the program.运行程序。 When it completes, you should see these results, as shown below:完成后,您应该看到这些结果,如下所示:

Using the Stack使用堆栈

In Jasmin, click File , New .在Jasmin中,单击“ 文件” ,“ 新建”

In the Code section, type in these instructions.在“代码”部分中,键入这些说明。

mov eax, 4 mov eax,4
mov ebx, 6 mov ebx,6
push eax推eax
push ebx推ebx
Before running the program, notice the ESP: it contains 4096, as shown below.在运行程序之前,请注意ESP:它包含4096,如下所示。

4096 is 0x1000 in hexadecimal--this is where the Stack ends. 4096是十六进制的0x1000 - 这是堆栈结束的地方。

Scroll down in the Memory pane to see the last values.在“内存”窗格中向下滚动以查看最后的值。 As show above, the last location is at 0xFFC.如上所示,最后一个位置是0xFFC。 This value is 32 bits long, so it contains four bytes, at locations 0xFFC, 0xFFD, 0xFFE, and 0xFFF.该值为32位长,因此它包含四个字节,位于0xFFC,0xFFD,0xFFE和0xFFF。 The ESP points to the next byte, 0x1000. ESP指向下一个字节0x1000。

Understanding Push了解推

At the top of the Jasmin window, click the green Run button.在Jasmin窗口的顶部,单击绿色的“运行”按钮。

These instructions move the number 4 into eax, and the number 6 into ebx.这些指令将数字4移动到eax,将数字6移动到ebx。 Then both values are pushed onto the stack.然后将两个值都压入堆栈。

Notice these things, as shown below:注意这些事情,如下所示:

Understanding Pop了解流行音乐

Add a pop instruction to your code, so it now looks like this:在代码中添加一条pop指令,现在它看起来像这样:
mov eax, 4 mov eax,4
mov ebx, 6 mov ebx,6
push eax推eax
push ebx推ebx
pop ecx pop ecx
Run the code.运行代码。

Notice these things, as shown below:注意这些事情,如下所示:

Reversing a Sequence反转序列

In Jasmin, click File , New .在Jasmin中,单击“ 文件” ,“ 新建”

In the Code section, type in these instructions.在“代码”部分中,键入这些说明。

mov eax, 1 mov eax,1
mov ebx, 2 mov ebx,2
mov ecx, 3 mov ecx,3
mov edx, 4 mov edx,4
push eax推eax
push ebx推ebx
push ecx推ecx
push edx推edx
pop eax流行的eax
pop ebx pop ebx
pop ecx pop ecx
pop edx 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.但是,由于堆栈是FILO(先进先出)结构,因此会反转值的顺序。

Push the Step four times to execute only the first four instructions, as shown below:按下Step四次只执行前四条指令,如下所示:

You see the values 1, 2, 3, and 4 loaded into the EAX, EBX, ECX, and EDX registers, as shown below.您会看到加载到EAX,EBX,ECX和EDX寄存器中的值1,2,3和4,如下所示。

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.您会看到将值1,2,3和4压入堆栈,如下所示。

Push the Step four more times to execute the remaining four instructions.再按第四以执行剩余的四条指令。

Now the registers contain these values:现在寄存器包含以下值:

as shown below.如下所示。


ED 304.1: Secret Message (10 pts) ED 304.1:秘密消息(10分)

Download this code and run it in Jasmin.下载此代码并在Jasmin中运行它。

p1xJas.asm p1xJas.asm

The code loads encrypted values onto the stack, decrypts them to place a secret message in ASCII into memory, and then erases the memory.代码将加密值加载到堆栈中,对其进行解密以将ASCII中的秘密消息放入内存中,然后擦除内存。

In the bottom-center pane of Jasmin, click Console to see the message, as shown below.在Jasmin的底部中心窗格中,单击“ 控制台”以查看消息,如下所示。

Use Jasmin to run the code until it has decrypted the message, but has not erased it yet.使用Jasmin运行代码,直到它解密了消息,但尚未删除它。

That message is the flag.那条消息就是旗帜。


Modified for WCIL 5-21-19修改为WCIL 5-21-19