*The basic steps of tasks (1), (2) and (3) are the same. Only the experimental steps of (1) are listed here
Step 1: paste the code to be used into the masm folder.
Step 2: compile, connect and debug.
Step 3: use the r command to view the value of each register.
cs is the segment address of code, DS is the segment address of data, and ss is the segment address of stack. This is because the statement in front of the code: assume cs:code, ds:data, ss:stack
Step 4: disassemble with the u command. Note that the disassembly is a code segment, so the u command should be followed by cs.
Step 5: execute with the g command. According to the code obtained by disassembly, execute before mov ax, 4c00. The use of the g command here is the use of breakpoints.
Step 6: use the d command to view the value of the data section. Since the segment address of data is DS, view 16 bytes from ds: 0 to ds: f.
*The steps of task (2) and (3) are similar, so I won't list them here.
Experimental results:
Task 1:
Task 2:
Task 3:
Task 4:
Task 1 modification:
Task 2 modification:
Task 3 modification:
Conclusion: it can be seen from disassembly that only Experiment 3 can run normally after changing end start to end.
Analysis: the entry of the start provider, so that cs: ip points to the first instruction to be executed. In the code of task 1 and task 2, the assembly instruction code segment is not at the beginning, so cs: ip is at the default beginning; The assembly instruction code of task 3 is at the beginning, and cs: ip just points to her.
The fourth question about task 2: lift ex5_1 as an example; The segment address where the data is stored is ds.
①ex5_1 source code:
assume cs:code, ds:data, ss:stack data segment dw 0123h, 0456h, 0789h, 0abch, 0defh, 0fedh, 0cbah, 0987h data ends stack segment dw 0, 0, 0, 0, 0, 0, 0, 0 stack ends code segment start: mov ax,stack mov ss, ax mov sp,16 mov ax, data mov ds, ax push ds:[0] push ds:[2] pop ds:[2] pop ds:[0] mov ax,4c00h int 21h code ends end start
After compiling the connection and running, use the r command to view, DS = 075a, SS = 076b, CS = 076c, which means that 10h, i.e. 16 bytes of space is allocated to the data paragraph.
②ex5_1_2 source code (the byte in the data paragraph gives 17 bytes of data): (the value of each register in task 3 can also be used in this step)
assume cs:code, ds:data, ss:stack data segment dw 0123h, 0456h, 0789h, 0abch, 0defh, 0fedh, 0cbah, 0987h,0123h data ends stack segment dw 0, 0, 0, 0, 0, 0, 0, 0 stack ends code segment start: mov ax,stack mov ss, ax mov sp,16 mov ax, data mov ds, ax push ds:[0] push ds:[2] pop ds:[2] pop ds:[0] mov ax,4c00h int 21h code ends end start
After compiling the connection and running, use the r command to view, DS = 075a, SS = 076c, CS = 076d, which means that 20h, or 32 bytes, is allocated to the data paragraph.
Conclusion: from this point of view, the stored data is less than 16 bytes, and 16 bytes of space is allocated to him; If the stored data is more than an integer multiple of 16 bytes, an entire 16 byte space will be allocated to the redundant data less than 16 bytes.
Answer: (N/16+1)*16
In addition, in the process of modifying the program, if English characters are written into Chinese characters, such as "," write "," write ", the following errors will appear:
Task 5:
Source code:
assume cs:code, ds:a, es:b, ss:c a segment db 1,2,3,4,5,6,7,8 a ends b segment db 1,2,3,4,5,6,7,8 b ends c segment db 8 dup(0) c ends code segment start: mov ax,a mov ds,ax mov ax,b mov es,ax mov ax,c mov ss,ax mov cx,8 mov bx,0 s: mov al, ds:[bx] add al, es:[bx] mov ss:[bx],al inc bx loop s mov ax,4c00h int 21h code ends end start
① Compiling and connecting
② debug execute the d command to view the c segment
③ u command disassembly, g command execution
④ d command view segment c
Task 6:
assume cs:code,ds:a,ss:b a segment dw 1,2,3,4,5,6,7,8,9,0ah,0bh,0ch,0dh,0eh,0fh,0ffh a ends b segment dw 8 dup(0) b ends code segment start: mov ax,a mov ds,ax mov ax,b mov ss,ax mov sp,10H mov bx,0 mov cx,8 s:push [bx] add bx,2 loop s mov ax,4c00h int 21h code ends end start
① Compiling and connecting
② d command to view the ss segment before execution
③ debug execution, r command to view the initial value of each register, u command disassembly, g command breakpoint execution
④ d command to view the ss segment after execution