Assembler Wang Shuang-Course Design 1

Source: Internet
Author: User
Tags mul

I recently learned CompilationProgramWang Shuang's Compilation Program, after some efforts, finally achieved the first curriculum design, establish a document as evidence, casuallyCodeThe write is poor, but the function is finally implemented.

I. Lab requirements

Output Data in experiment 7 on the screen

Ii. Design Ideas

1. Compile the program in experiment 7 as a sub-process finishing. Call the program in the main program to obtain the table segment data in the seven specified formats of the experiment. Set ES: BX points to the first row in the table segment

2. Create a data cache buffer and set DS: Si to point to buffer

3. for strings, read from the table and write to the buffer, and write 0 at the end. For numeric values, directly call the DTOC written in experiment 10 to convert it to the buffer.

4. Call show_str in experiment 10 to display the string after each buffer data update.

The required effect is

 

 

 

Code:

Assume Cs: Code
Data Segment
Dd 1975,1976, 1977,1978, 1979,1980, 1981,1982, 1983,1984, 1985,1986, 1987,1988, 1989,1990, 1991,1992, 1993,1994, 1995
Dd 5937000
Dd 130,220,476,778,100, 7, 17800
Dd 42,104, 85,210,123,111,105,125,140,136,153,211,199,209,224,239,260,304,333
DB 16 DUP (0)
Data ends
Stack segment
DB 64 DUP (0)
Stack ends
Code segment
Start:
MoV ax, Data
MoV ds, ax
MoV ax, stack
MoV SS, ax
MoV sp, 64
MoV ax, 0b800h
MoV es, ax
MoV Di, 336
MoV Si, 0
MoV BH, 2
MoV BL, 2
MoV CX, 4

M:
Push CX
MoV CX, 21
S:
MoV dx, DS: [Si + 2]
MoV ax, DS: [Si]
Call d2c
MoV DH, BH
MoV DL, BL
Call show_str
INC BH
Add Si, 4
Loop s

MoV BH, 2
Add BL, 10
Pop CX
Loop m



MoV ax, 4c00h
Int 21 h
; Subroutine description
; Name: d2c
Function: convert a number into a string and place it in a memory unit starting with [di ].
; Parameter: (dx) = high 16-bit (ax) of DWORD data = low 16-bit of DWORD data
; Return Value: A string ending with 0, which is placed in the memory unit where [di] is the starting address.
D2c:
Push di
Push CX
Push DX
Push BX
MoV BX, 1
D2c_s:
Call divdw
Add CX, 30 h; the remainder is converted to a string.
Push CX
MoV CX, ax
Jcxz OK

INC BX
JMP d2c_s

OK:
MoV CX, BX

Reverse:; put strings in the correct order
Pop ax

MoV [di], Al
INC di

Loop reverse
MoV Al, 0
MoV [di], Al
INC di
Pop BX
Pop DX
Pop CX
Pop di

RET


; Subroutine description
; Name: divdw
Function: conducts Division operations without overflow. The divisor type is DWORD, the divisor type is word, and the result is DWORD.
; Parameter: (dx) = high 16-bit (ax) of DWORD data = low 16-bit (CX) of DWORD data = Divisor
; Return: (dx) = high 16-bit (ax) of the result = low 16-bit (CX) of the result = Remainder
Example: Calculate 1000000/10 (f4240h/0ah)
Divdw:
Push ax; low 16-bit divisor into Stack
MoV ax, DX
MoV dx, 0
MoV CX, 10
Div CX; the result provider is placed in ax, and the remainder is placed in dx.
MoV CX, ax; temporary storage provider
Pop ax; Retrieve the low 16-bit value
Push CX; save vendor into Stack

MoV CX, 10
Div CX

MoV CX, DX; add remainder to CX
Pop DX; the high 16 bits of the merchant are stored in dx, and the result in ax is the low 16 bits of the merchant.

RET


Show_str:; subroutine, the first address of the string stored in BX, and the first address of the Character Buffer in Si
Register into Stack
Push DX
Push CX
Push BX
Push Si
MoV ax, 160
MoV Cl, DH
Mul Cl
MoV BX, ax
MoV ah, 0
MoV Al, DL
MoV Cl, 2
Mul Cl
Add ax, BX
MoV Si, ax
MoV BX, 0
STR:; display string
MoV Cl, [di + BX]; judge whether to read 0
MoV CH, 0
Jcxz str_ OK
MoV ES: [Si], Cl; move string
MoV ES: [Si + 1], 02 h
Add Si, 2
INC BX
JMP Str
Str_ OK:; register output Stack
Pop Si
Pop BX
Pop CX
Pop DX
RET
; Return






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.