Training assembly language design -- delete all zero items in the array

Source: Internet
Author: User
The functions implemented by the program are as follows:
The address of the 100-word group is MEM, and all zero items in the array are deleted by the program,
And compress the data to the forward, and add the remaining parts of the array to zero.
Data Segment
Mem DW 20 DUP (0, 1, 2, 3, 4)
N equ $-Data
Data ends
Stack segment
Stapn DW 50 DUP (?)
Stack ends
Code segment
Main proc far
Assume DS: data, CS: code, SS: Stack
Start:
; Set up stack to retuan
PUSH DS
Sub ax, ax
PUSH AX
; Set DS register to current segment
MoV ax, Data
MoV ds, ax
MoV es, ax
MoV ax, stack
MoV SS, ax
; Maim part of the code goes here
MoV CX and 100
Lea Di, Mem
MoV sp, Di
Add SP, N; get the address of the last cell of the array and add 2
Push CX
Push di
Add Di, n
Again: mov dx, 0; this part cyclically completes the content of the 100 characters after the array men
MoV [di], DX; complete zero so that only zero items must be deleted in subsequent programs.
Add Di, 2; do not add zero in the last part of the array
Loop again
Pop di
Pop CX; record the number of external Loops
Loop1: Test [di], 0 ffffh
Jnz continue
MoV Si, di; EA that records 0 items
Next: mov ax, [Si + 2]; implements forward Compression
MoV [Si], ax
Add Si, 2
CMP Si, SP
Jae continue
JMP next
Continue: Add Di, 2
Loop loop1
Exit: Ret
Main endp
;--------------------------------------------------
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.