【4-8】求从TABLE开始的10个无符号字节数的和,,结果放在SUM字单元中:
代码如下:
DATAS SEGMENT
TABLE DB 12H,23H,34H,45H,56H ;此处输入数据段代码
DB 67H,78H,89H,90H,0FDH
SUM DW ?
DATAS ENDS
;
ESEG SEGMENT
ESEG ENDS
STACKS SEGMENT
;此处输入堆栈段代码
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
MOV ES,AX
LEA SI,TABLE
MOV CX,10
XOR AX,AX
NEXT: ADD AL,[SI]
ADC AH,0
INC SI
LOOP NEXT
MOV SUM, AX
HLT
CODES ENDS
END START
【4-12】从键盘上输入字符串”HELLO ”,并在结尾处加结束标志’$’。
代码如下:
DATAS SEGMENT
STRING DB 10,0,10 DUP(?)
DATAS ENDS
;
ESEG SEGMENT
;
ESEG ENDS
STACKS SEGMENT
;此处输入堆栈段代码
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
LEA DX,STRING
MOV AH,0AH
INT 21H
MOV CL,STRING+1
XOR CH,CH
ADD DX,CX
MOV BX,DX
MOV BYTE PTR[BX+2],
MOV AH,4CH
INT 21H
HLT
CODES ENDS
END START
输入字符结果:
【4-13】在屏幕上依次显示”1”,”2”,”3”,”A”,”B”,”C”6个字符。
代码如下:
DATAS SEGMENT
STRING DB
DATAS ENDS
;
ESEG SEGMENT
;
ESEG ENDS
STACKS SEGMENT
;此处输入堆栈段代码
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
LEA BX,STRING
MOV CX,6D
LPP: MOV AH,2
MOV DL,[BX]
INC BX
INT 21H
LOOP LPP
MOV AH,4CH
INT 21H
HLT
CODES ENDS
END START
【4-14】在屏幕上显示欢迎字符串“Hello World!”。
代码如下:
DATAS SEGMENT
STRING DB
DATAS ENDS
;
ESEG SEGMENT
;
ESEG ENDS
STACKS SEGMENT
;此处输入堆栈段代码
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
LEA DX,STRING
MOV AH,09H
INT 21H
MOV AH,4CH
INT 21H
;HLT
CODES ENDS
END START
【4-15】在键盘输入一串字符,在字符串尾插入’$’,并显示该字符:
代码如下:
DATAS SEGMENT
BUFSIZE DB 50 ;此处输入数据段代码
ACTLEN DB ?
CHARS DB 50 DUP(?)
DATAS ENDS
STACKS SEGMENT
;此处输入堆栈段代码
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
MOV DX,OFFSET BUFSIZE
MOV AX,0AH
INT 21H
XOR CX,CX
MOV CL,ACTLEN
MOV DX,OFFSET CHARS
MOV BX,DX
ADD BX,CX
MOV BYTE PTR[BX],
MOV AH,09H
INT 21H
MOV AH,4CH
INT 21H
CODES ENDS
END START
【4-16】编写S=86H+34H-21H的程序:
DATAS SEGMENT
NUM DB 86H,34H,21H ;此处输入数据段代码
RESULT DW ?
DATAS ENDS
STACKS SEGMENT
;此处输入堆栈段代码
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
LEA SI,NUM
LEA DI,RESULT
MOV AL,[SI]
MOV BL,[SI+1]
MUL BL
MOV BL,[SI+2]
MOV BH,0
SUB AX,BX
MOV [DI],AX
MOV AH,4CH
INT 21H
CODES ENDS
END START
【4-17】内存TABLE开始的连续16个单元中存放着0~15的平方值,查表求DATA中任意数X(0·15)的平方值,并将结果放在RESULT中:
代码如下:
DATAS SEGMENT
TABLE DB 0,1,4,9,16,25,36,49,64,81,100,121,144,169,196,225;定义平方表
DATA DB ?
RESULT DB ?
DATAS ENDS
STACKS SEGMENT
DB 100 DUP(?) ;此处输入堆栈段代码
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
MOV DX,STACKS
mov SS,AX
LEA BX,TABLE
MOV AH,0
MOV AL,DATA
ADD BX,AX
MOV AL,[BX]
MOV RESULT,AL
MOV AH,4CH
INT 21H
CODES ENDS
END START
【4-18】编写程序,将数据区中以BUFFER为首地址的100个字节单元清零:
代码如下:
DATAS SEGMENT
BUFFER DB 100 DUP(?)
COUNT DW 100
DATAS ENDS
;
STACKS SEGMENT
DW 32 DUP(?) ;此处输入堆栈段代码
STACKS ENDS
;
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
MOV AX,STACKS
mov SS,AX
MOV CX,COUNT
LEA BX,BUFFER
ADD CX,BX
AGAIN: MOV BYTE PTR[BX],0
INC BX
CMP BX,CX
JB AGAIN
MOV AH,4CH
INT 21H
CODES ENDS
END START
【4-19】当前数据段中DATA1开始的顺序80个单元中,存放着80位同学的某门功课的考试成绩(0~100),编写程序统计各分数段的人数,将结果放到同一数据段的DATA2开始的5个单元中:
代码如下:
DATAS SEGMENT
DATA1 DB 80 DUP(?)
DATA2 DB 5 DUP(?)
DATAS ENDS
;
STACKS SEGMENT
;此处输入堆栈段代码
STACKS ENDS
;
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
MOV CX,80
LEA SI,DATA1
LEA DI,DATA2
ADD CX,BX
AGAIN: MOV AL,[SI]
CMP AL, 90
JC NEXT1
INC BYTE PTR[DI]
JMP STO
NEXT1: CMP AL,80
JC NEXT2
INC BYTE PTR[DI+1]
JMP STO
NEXT2: CMP AL,70
JC NEXT3
INC BYTE PTR[DI+2]
JMP STO
NEXT3: CMP AL,60
JC NEXT4
INC BYTE PTR[DI+3]
JMP STO
NEXT4: INC BYTE PTR[DI+4]
STO: INC SI
LOOP AGAIN
MOV AH,4CH
INT 21H
CODES ENDS
END START
【4-20】把从MEM单元开始的100个16位无符号数从大到小的顺序排列。
代码如下:
DATAS SEGMENT
MEM DW 100 DUP(?)
DATAS ENDS
;
STACKS SEGMENT
;此处输入堆栈段代码
STACKS ENDS
;
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
LEA DI,MEM
MOV BL,99
NEXT1: MOV SI,DI
MOV CL,BL
NEXT2: MOV AX,[SI]
ADD SI,2
CMP AX,[SI]
JNC NEXT3
MOV DX,[SI]
MOV [SI-2],DX
MOV [SI],AX
NEXT3: DEC CL
JNZ NEXT2
DEC BL
JNZ NEXT1
MOV AH,4CH
INT 21H
CODES ENDS
END START