1. count the number of negative elements in a font Array
. 486
Data Segment
Array DW 54,-1050,-6800, 0, 853 ,-
Count equ $-array; space occupied by statistics
Result DW?
Data ends
Code segment
Assume Cs: code, DS: Data
Start:
MoV ax, Data
MoV ds, ax
MoV Si, offset array; pointer Initialization
MoV CX, count/2; the number of statistical data is stored in CX
ClD
MoV dx, 0
LL: lodsw; count to ax
BT ax, 15
JNC next; determine whether it is a negative number
Inc dx; counter plus 1
Next: loop LL
MoV result, DX
MoV ah, 4ch
Int 21 h
Code ends
End start
2. Sorting
Data Segment
Block dB 22 h, 55 h, 11 h, 78 h; N 4
Data ends
Code segment
Assume Cs: code, DS: Data
Start:
MoV ax, Data
MoV ds, ax
Lea BX, block; External Loop pointer Initialization
MoV CX, 3; initialize the External Loop counter
Lp1: mov Si, BX; Inner Loop pointer Initialization
MoV dx, CX; inner cycle counter Initialization
MoV Al, [Si]
Lp2: CMP Al, [Si + 1]
Jge lp3
Xchg Al, [Si + 1]
Lp3: Inc Si; modify the inner loop pointer
Dec DX
Jnz lp2
MoV [BX], Al; large number
Inc bx; modify the inner loop pointer
Loop lp1
MoV ah, 4ch
Int 21 h
Code ends
End start
3. Check and count data segmentstrn dB 'hlfhal $ 'count DB? Data endscode segment assume Cs: code, DS: datastart: mov ax, data mov ds, ax mov DL, 0; counter clearing Lea Si, strn; pointer initialization LL: lodsb; read a number, Si moves CMP Al, '$'; to determine whether to end je exit; when an end character exits JP ll; no need to verify the conversion to another or Al, 80 h; add the verification bit mov [SI-1], Al; Save the verified value to INC dl; Add 1 JMP ll Exit: mov count, DL to the counter; add DL to the result, 30 h mov ah, 02 h int 21 h mov ah, 4ch int 21 H code ends end start4. find
Data Segment
First DB 12 h, 44 h, 65 h, 3 h, 0 h
N dw?
Data ends
Code segment
Assume Cs: code, DS: data, ES: Data
Start:
MoV ax, Data
MoV ds, ax
MoV es, ax
MoV dx, 0; counters cleared
MoV CX, 5; set the number of cycles
Lea Si, first; pointer Initialization
LL: mov Al, [Si]; fetch number
INC Si; Modify pointer
CMP Al, 0; compared with 0
Je exit; exit
Inc dx; counter plus 1
Loop LL
Exit: mov N, DX; save result
MoV ah, 4ch
Int 21 h
Code ends
End start