Java教程

用汇编指令编码和调试

本文主要是介绍用汇编指令编码和调试,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

目录
  • 实验任务2
  • 实验任务3
  • 实验任务4
  • 实验任务5
  • 实验任务6
  • 实验任务7

实验任务2

因为是 ROM 里的数据,所以不可修改。

实验任务3

实验任务4

 -a
 mov ax, 20
 mov ds, ax
 mov ss, ax
 mov sp, 30
 push [0] 	; 执行后,寄存器(sp) = 2E
 push [2] 	; 执行后,寄存器(sp) = 2C
 push [4] 	; 执行后,寄存器(sp) = 2A
 push [6] 	; 执行后,寄存器(sp) = 28
 pop [6]	; 执行后,寄存器(sp) = 2A
 pop [4] 	; 执行后,寄存器(sp) = 2C
 pop [2]	; 执行后,寄存器(sp) = 2E
 pop [0]	; 执行后,寄存器(sp) = 30
  1. 逻辑地址: ss:30H 物理地址: ss:30H = $20H \times 16 + 30H = 230H$

  2. 前:

    后:

    不变

实验任务5

  1. 没有暂停。 mov sp, 30 立刻执行了。

    参考 MASM Reference[1] 和 64-ia-32-architectures-software-developer-vol-3a-part-1-manual[2]

    MASM Reference: Moves the value in the source operand to the destination operand. If the destination operand is SS, interrupts are disabled until the next instruction is executed (except on early versions of the 8088 and 8086).

  2. 栈空间00220H ~ 0022fH内存单元值是调用 interrupt-handler 得到的数据。[3]

    When the processor performs a call to the exception- or interrupt-handler procedure:
    When the stack switch occurs:
    a. The segment selector and stack pointer for the stack to be used by the handler are obtained from the TSS
    for the currently executing task. On this new stack, the processor pushes the stack segment selector and
    stack pointer of the interrupted procedure.
    b. The processor then saves the current state of the EFLAGS, CS, and EIP registers on the new stack (see
    Figures 6-4).
    c. If an exception causes an error code to be saved, it is pushed on the new stack after the EIP value.

实验任务6

  1. 源码

    assume cs:code
    
    code segment
    start:
    	mov cx, 10
    	mov dl, '0'
    s: 	mov ah, 2
    	int 21h
    	add dl, 1
    	loop s
    	
    	mov ah, 4ch
    	int 21h
    code ends
    end start
    
  2. 汇编链接过程截图以及运行可执行程序的运行结果截图

  1. 程序段前缀PSP的截图

实验任务7

assume cs:code
code segment
    mov ax, cs
    mov ds, ax
    mov ax, 0020h
    mov es, ax
    mov bx, 0
    mov cx, 17h
s:  mov al, [bx]
    mov es:[bx], al
    inc bx
    loop s
    mov ax, 4c00h
    int 21h
code ends
end
  • By default, instructions that use direct memory addressing use the DS register.[4]我们需要 mov al, [bx] 从 cs 段开始复制数据,所以 mov ds, ax
  • 通过 debug 直接查出需要复制的数据占 17H 字节。也可以查手册一条指令一条指令计算,太麻烦了。

上古 8086,参考好难找,Intel 64 手册凑合用。


  1. Page 105, Instructions, MOV Move Data. Microsoft ® MASM Assembly-Language Development System Version 6.1 ↩ ↩︎

  2. 6.8.3 Masking Exceptions and Interrupts When Switching Stacks. Intel® 64 and IA-32 Architectures Software Developer’s Manual ↩︎

  3. 6.12.1 Exception- or Interrupt-Handler Procedures. Intel® 64 and IA-32 Architectures Software Developer’s Manual ↩︎

  4. Direct Memory Operands. Microsoft ® Programmer’s Guide ↩︎

这篇关于用汇编指令编码和调试的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!