Chapter 6 of Wang Shuang's compilation contains multiple program operations

Source: Internet
Author: User

; Chapter 6 contains procedures for multiple segments
; 1, the following program implementation uses memory 0-0 in sequence ~ In unit 0: 15, the data in the program is rewritten to complete the program:
Assume Cs: codesg
Codesg segment
DW 0123 H, 0456 H, 0789 H, 0 abch, 0 defh, 0 fedh, 0 cdah, 0987 H
Start: mov ax, 0
MoV ds, ax
MoV BX, 0
MoV CX, 8
S: mov ax, [BX]
MoV Cs: [BX], ax
Add Bx, 2
Loop s

MoV ax, 4c00h
Int 21 h
Codesg ends
End start

; 2. The following program uses memory 0-0 in sequence ~ The content in unit 0: 15 changes the data in the program, and the data is transferred using stacks. Stack space is set in the program. Completion program:
Assume Cs: codesg
Codesg segment
DW 0123 H, 0456 H, 0789 H, 0 abch, 0 defh, 0 fedh, 0 cbah, 0987 H
DW 0, 0, 0, 0, 0, 0, 0, 0
Start: mov ax, CS
MoV SS, ax
MoV sp, 36

MoV ax, 0
MoV ds, ax
MoV BX, 0
MoV CX, 8
S: Push [BX]
Pop Cs: [BX]
Add Bx, 2
Loop s

MoV ax, 4c00h
Int 21 h
Codesg ends
End start

Lab 5: Write and Debug Programs with multiple segments
1. Compile and connect the following program, load and track it with debug, and then answer the question.
Assume Cs: code, DS: data, SS: Stack
Data Segment
DW 0123 H, 0456 H, 0789 H, 0 abch, 0 defh, 0 cbah, 0987 H
Data ends

Stack segment
DW 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 21 h
 
Code ends
End start

1. What is the data in the data segment before the program returns the CPU execution program?
;-D 0b8d: 0
; 0b8d: 0000 23 01 56 04 89 07 BC 0a-ef 0d Ba 0C 87 09 00 00 #. V .............

; 2. CPU execution program. Before the program returns, cs =, Ss =, DS =
; Cs = 0b8f, Ss = 0b8e, DS = 0b8d

3. After the program is loaded, the segment address of the code segment is X, the segment address of the data segment is the X-2
; Segment address is X-1.

 

2. Compile and connect the following program, use DEBUG to load, track, and answer questions.

Assume Cs: code, DS: data, SS: Stack
Data Segment
DW 0123 H, 0456 H
Data ends

Stack segment
DW 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 21 h
 
Code ends
End start

1. What is the data in the data segment before the program returns the CPU execution program?
;-D 0b8d: 0
; 0b8d: 0000 23 01 56 04 00 00 00 00-00 00 00 00 00 00 00 00 #. V .............

; 2. CPU execution program. Before the program returns, cs =, Ss =, DS =
; Cs = 0b8f, Ss = 0b8e, DS = 0b8d

3. After the program is loaded, the segment address of the code segment is X, the segment address of the data segment is the X-2
; Segment address is X-1.

4. For the following defined segments:
; Name segment
;...
; Name Ends
If the data in the segment occupies n Bytes, the actual space occupied by the segment after the program is loaded is (N/16 + 1) * 16

3. Compile and connect the following program, use DEBUG to load and track the program, and then answer the question.
Assume Cs: code, DS: data, SS: Stack
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 21 h

Code ends
Data Segment
DW 0123 H, 0456 H
Data ends

Stack segment
DW 0, 0
Stack ends

End start

1. What is the data in the data segment before the program returns the CPU execution program?
-D 0b90: 0
0b90: 0000 23 01 56 04 00 00 00 00 00 00 00 00 00 00 00 00 #. V .............

; 2. CPU execution program. Before the program returns, cs = 0b8d, Ss = 0b91, DS = 0b90

3. After the program is loaded, the segment address of the code segment is X, the segment address of the data segment is x + 3, and the segment address of the stack segment is x + 4.

4. If you change the end start of the last pseudocommand in question 1, 2, 3 to end, that is, the program entry is not specified, which program can still be correctly executed? Please explain the reason

The third program can be correctly executed. If no entry is specified, the program runs after PSP.
After PSP, the first program is the data segment, the second program is the data segment, and only the third program is the code segment,
So only the third one can be correctly executed.

5. The program is as follows. Write the code in the code segment, add the data in section A and section B in sequence, and save the result to section C.
Assume Cs: Code
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 0, 0, 0, 0, 0, 0
C ends

Code segment

Start: mov ax,
MoV ds, ax
 
MoV BX, 0
MoV CX, 4
 
S: mov dx, DS: [BX]
Add dx, DS: [bx + 16]
MoV DS: [bx + 32], DX
Add Bx, 2
Loop s
 
MoV ax, 4c00h
Int 21 h
 
Code ends
End start

Test results:
-D 0b8d: 0
0b8d: 0000 01 02 03 04 05 06 07 08-00 00 00 00 00 00 00 ................
0b8d: 0010 01 02 03 04 05 06 07 08-00 00 00 00 00 00 00 ................
0b8d: 0020 02 04 06 08 0a 0C 0e 10-00 00 00 00 00 00 00 ................

6. The program is as follows. Write the code in the code segment and use the push command to save the first eight fonts in Section A to Section B in reverse order.

Assume Cs: Code
A segment
DW 1, 2, 3, 4, 5, 6, 7, 8, 9, 0ah, 0bh, 0ch, 0dh, 0eh, 0fh, 0ffh
A ends

B segment
DW 0, 0, 0, 0, 0, 0
B ends
Code segment

Start: mov ax,
MoV ds, ax
MoV BX, 0
MoV CX, 8

MoV ax, B
MoV SS, ax
MoV sp, 16

S: Push [BX]
Add Bx, 2
Loop s

MoV ax, 4c00h
Int 21 h
Code ends
End start

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.