实验1
1.略
2.
1、略
2、注意16进制转换10进制
3、无法改变,应为ROM具有‘只读’属性
4、B8100H单元为彩色字符显存,在此单元内写入数据直接会显示在显示屏上
实验2
1、略
2、
1.
AX= C0EAH
AX= C0FCH
BX= 30F0H
BX= 6021H
SP= 00FE 220FE C0FCH
SP= 00FC 220FC 6021H
SP= 00FE 6021H
SP= 0100 C0FCH
SP= 00FE 220FE 30F0H
SP= 00FC 220FC 2F31H
2.
解:t命令为单步中断,在执行的时候CPU会保护现场,即按顺序把标志寄存器、CS、IP的值和操作数据放入栈中,此题是关于后面章节的中断问题。
实验3
1、略
2、
AX= 2000H
SS= 2000H
SP= 0
SP= AH
AX= 0
SP= CH
BX= 0
SP= EH
SP= CH
SP= AH
SP= CH
SP= EH
3、略
实验4
1、
ASSUME CS:CODE
CODE SEGMENT
MOV AX,0020H
MOV DS,AX
MOV BX,0
MOV AL,0
MOV CX,64
S:
MOV DS:[BX],AL
INC BX
INC AL
LOOP S
MOV AX,4C00H
INT 21H
CODE ENDS
END
2、
ASSUME CS:CODE
CODE SEGMENT
MOV AX,0020H
MOV DS,AX
MOV BX,0
MOV CX,64
S:
MOV DS:[BX],BL
INC BX
LOOP S
MOV AX,4C00H
INT 21H
CODE ENDS
END
3、
MOV AX,CS
MOV CX,17H
实验5
1、
1.不变
2.0772H、0771H、0770H
3.X-2、X-1
2、
1.不变
2.0072H、0771H、0770H
3.X-2、X-1
4.(N/16+1)*16
3、
1.不变
2.0072H、0771H、0770H
3.X-2、X-1
4、
第3能正确执行,如果不指名程序入口,编译器自动默认整个代码的第一条指令为程序的入口
5、
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,0,0
C ENDS
CODE SEGMENT
START: MOV AX,A
MOV DS,AX
MOV BX,0
MOV AL,0
MOV CX,8
S:
MOV AL,[BX]
ADD AL,[16+BX]
MOV [32+BX],AL
INC BX
LOOP S
MOV AX,4C00H
INT 21H
CODE ENDS
END START
6、
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,0,0
B ENDS
CODE SEGMENT
START:MOV AX,A
MOV DS,AX
MOV BX,0
MOV CX,8
S:
PUSH [BX]
ADD BX,2
LOOP S
MOV BX,0
MOV CX,8
S1: POP [20H+BX]
ADD BX,2
LOOP S1
MOV AX,4C00H
INT 21H
CODE ENDS
END START
实验6
1、略
2、
ASSUME CS:CODE,SS:STACK,DS:DATA
STACK SEGMENT
DW 0,0,0,0,0,0,0,0
STACK ENDS
DATA SEGMENT
DB '1. display '
DB '2. brows '
DB '3. replace '
DB '4. modify '
DATA ENDS
CODE SEGMENT
START: MOV AX,STACK
MOV SS,AX
MOV SP,16
MOV AX,DATA
MOV DS,AX
MOV BX,0
MOV SI,3
MOV CX,4
S: MOV AL,[BX][SI]
AND AL,11011111B
MOV [BX][SI],AL
CMP SI,6 ;CMP比较指令,此处使用了后面学到的知识点
JE OK ;相等就跳到标号处
INC SI
JMP S
OK:
MOV SI,3
ADD BX,16
LOOP S
MOV AX,4C00H
INT 21H
CODE ENDS
END START
实验7
ASSUME CS:CODE,DS:DATA,SS:STACK
DATA SEGMENT
DB '1975','1976','1977','1978','1979','1980','1981','1982','1983'
DB '1984','1985','1986','1987','1988','1989','1990','1991','1992'
DB '1993','1994','1995'
;以上是表上21年的21个字符串
DD 16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514
DD 345980,590827,803530,1183000,1843000,2759000,3753000,4649000,5937000
;以上是表上21年公司总收入的21个dword型数据
DW 3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226
DW 11542,14430,15257,17800
;以上是表上21年公司雇佣人数的21个word数据
DATA ENDS
TABLE SEGMENT
DB 21 DUP('YEAR SUMM NE ?? ')
TABLE ENDS
STACK SEGMENT
DB 128 DUP(0)
STACK ENDS
CODE SEGMENT
START:MOV AX,STACK
MOV SS,AX
MOV SP,128
MOV AX,DATA
MOV DS,AX
MOV AX,TABLE
MOV ES,AX
MOV BX,0
MOV BP,0
MOV SI,0
MOV CX,21
S:
PUSH CX
MOV AX,WORD PTR DS:[SI]
MOV WORD PTR ES:[BX],AX
MOV AX,WORD PTR DS:[SI+2]
MOV WORD PTR ES:[BX+2],AX
MOV AX,WORD PTR DS:[SI+84]
MOV WORD PTR ES:[BX+5],AX
MOV DX,WORD PTR DS:[SI+86]
MOV WORD PTR ES:[BX+7],DX
MOV CX,WORD PTR DS:[BP+168]
MOV WORD PTR ES:[BX+10],CX
DIV CX
MOV WORD PTR ES:[BX+13],AX
ADD BX,16
ADD SI,4
ADD BP,2
POP CX
LOOP S
MOV AX,4C00H
INT 21H
CODE ENDS
END START
实验8
可以
程序在编译完成的时候,JMP SHORT S1指令需要转移的位移已由编译程序在编译时算出,包含在转移指令的机器码中
当程序运行转移到标号S处时,JMP SHORT S1指令的机器码(包含需转移的位移)已写入此单元中,程序执行此转移指令((IP)=(IP)+8位位移)会转移到偏移地址0000处即程序的第一条指令处,所以程序能正常返回。
实验9
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
DB 'Welcome to masm!'
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA
MOV DS,AX
MOV BX,0
MOV AX,0B800H
MOV ES,AX
MOV DI,160*8+40*2
MOV CX,16
S: MOV AH,00000010B ;绿色
MOV AL,[BX]
MOV ES:[DI],AX
INC BX
ADD DI,2
LOOP S
MOV DI,160*9+40*2
MOV BX,0 ;重置
MOV CX,16
S1: MOV AH,00100100B ;绿底红色
MOV AL,[BX]
MOV ES:[DI],AX
INC BX
ADD DI,2
LOOP S1
MOV DI,160*10+40*2
MOV BX,0
MOV CX,16
S2: MOV AH,01110001B ;白底蓝色
MOV AL,[BX]
MOV ES:[DI],AX
INC BX
ADD DI,2
LOOP S2
MOV AX,4C00H
INT 21H
CODE ENDS
END START
实验10
1、
ASSUME CS:CODE,DS:DATA,SS:STACK
DATA SEGMENT
DB 'Welcome to masm!',0
DATA ENDS
STACK SEGMENT
DB 128 DUP(0)
STACK ENDS
CODE SEGMENT
START: MOV AX,DATA
MOV DS,AX
MOV SI,0
MOV AX,STACK
MOV SS,AX
MOV SP,128
MOV DH,8
MOV DL,3
MOV CL,2
CALL SHOW_STR
MOV AX,4C00H
INT 21H
SHOW_STR: PUSH BX
PUSH ES
PUSH DI
PUSH AX ;名称SHOW_STR
PUSH DX ;功能:在指定的位置,用指定的颜色,显示一个用0结束的字符串
PUSH CX ;参数:(dh)=行号(取值范围0-24),(dl)=列号(取值范围0-79)
PUSH SI ; (cl)=颜色,ds:si指向字符串的首地址
;返回:无
MOV BX,0B800H
MOV ES,BX
MOV DI,0
MOV AX,160
DEC DH
MUL DH
MOV DI,AX
MOV DH,0
ADD DX,DX
ADD DI,DX
MOV AH,CL
MOV CH,0
S: MOV CL,[SI]
JCXZ OK
MOV AL,CL
MOV ES:[DI],AX
INC SI
ADD DI,2
JMP S
OK: POP SI
POP CX
POP DX
POP AX
POP DI
POP ES
POP BX
RET
CODE ENDS
END START
2、
ASSUME CS:CODE,DS:DATA,SS:STACK
DATA SEGMENT
DD 1000000
DATA ENDS
STACK SEGMENT
DB 128 DUP(0)
STACK ENDS
CODE SEGMENT
START: MOV AX,DATA
MOV DS,AX
MOV AX,STACK
MOV SS,AX
MOV SP,128
MOV AX,DS:[0]
MOV DX,DS:[2]
MOV CX,10
CALL DIVDW
MOV AX,4C00H
INT 21H
DIVDW:MOV BX,AX ;名称:divdw
MOV AX,DX ;功能:进行不会产生溢出的除法运算,被除数为dword型,除数为word型,结果为dwrod型
MOV DX,0 ;参数:(ax)=dword型数据的低16位
DIV CX (dx)=dword型数据的高16位
PUSH AX (cx)=除数
MOV AX,BX ;返回:(dx)=结果的高16位,(ax)=结果的低16位
DIV CX (cx)=余数
MOV CX,DX
POP DX
RET
CODE ENDS
END START
3、
ASSUME CS:CODE,DS:DATA,SS:STACK
DATA SEGMENT
DW 123,12666,1,8,3,38
DW 48 DUP(0)
DATA ENDS
STACK SEGMENT
DB 128 DUP(0)
STACK ENDS
CODE SEGMENT
START: MOV AX,STACK
MOV SS,AX
MOV SP,128
MOV BX,0B800H
MOV ES,BX
MOV DI,0
MOV AX,DATA
MOV DS,AX
MOV SI,0
MOV BX,0
MOV BP,0
MOV CX,6
S0:
MOV AX,[SI]
CALL DTOC
ADD SI,2
ADD BP,16
LOOP S0
MOV BP,0
MOV DH,8
MOV DL,3
MOV CX,6
S5:
PUSH CX
MOV CL,2
CALL SHOW_STR
ADD BP,16
INC DH
POP CX
LOOP S5
MOV AX,4C00H
INT 21H
;-------------------------------------------------------
SHOW_STR: PUSH BX
PUSH ES
PUSH DI
PUSH AX
PUSH DX
PUSH CX
PUSH SI
PUSH BP
MOV AX,160
DEC DH
MUL DH
MOV DI,AX
MOV DH,0
ADD DX,DX
ADD DI,DX
MOV AH,CL
MOV CH,0
S: MOV CL,DS:[BP+16]
JCXZ OK
MOV AL,CL
MOV ES:[DI],AX
INC BP
ADD DI,2
JMP S
OK: POP BP
POP SI
POP CX
POP DX
POP AX
POP DI
POP ES
POP BX
RET
;--------------------------------------------------------
DTOC:PUSH DX
PUSH CX
PUSH AX
PUSH BX
PUSH DS
PUSH BP
S1:
MOV DX,0
MOV CX,10
DIV CX
MOV CX,AX
ADD DX,30H
PUSH DX
INC BX
JCXZ OK1
JMP S1
OK1: MOV CX,BX
S2: POP DX
MOV DS:[BP+16],DL
INC BP
LOOP S2
MOV BYTE PTR DS:[BP+16],0
POP BP
POP DS
POP BX
POP AX
POP CX
POP DX
RET
CODE ENDS
END START
实验11
ASSUME CS:CODE
DATASG SEGMENT
DB "Beginner's All-purpose Symbolic Instruction Code.",0
DATASG ENDS
CODE SEGMENT
START: MOV AX,DATASG
MOV DS,AX
MOV SI,0
CALL LETTERC
MOV AX,4C00H
INT 21H
LETTERC:CMP BYTE PTR DS:[SI],61H
JB OK
CMP BYTE PTR DS:[SI],7AH
JA OK
AND BYTE PTR DS:[SI],11011111B
OK:
INC SI
MOV CH,0
MOV CL,[SI]
JCXZ OK1
JMP LETTERC
OK1:
RET
CODE ENDS
END START
实验12
ASSUME CS:CODE
CODE SEGMENT
START: MOV AX,CS
MOV DS,AX
MOV SI,OFFSET DO0
MOV AX,0
MOV ES,AX
MOV DI,200H
MOV CX,OFFSET DO0END-OFFSET DO0
CLD
REP MOVSW
MOV AX,0
MOV ES,AX
MOV WORD PTR ES:[0*4],200H
MOV WORD PTR ES:[0*4+2],0
MOV AX,1000H
MOV BH,1
DIV BH
MOV AX,4C00H
INT 21H
DO0: JMP SHORT DOSTART
DB 'Overflow!'
DOSTART:MOV AX,CS
MOV DS,AX
MOV SI,202H
MOV AX,0B800H
MOV ES,AX
MOV DI,160*12+30*2
MOV AH,4
MOV CX,9
S:
MOV AL,[SI]
MOV ES:[DI],AX
INC SI
ADD DI,2
LOOP S
MOV AX,4C00H
INT 21H
DO0END: NOP
CODE ENDS
END START
实验13
1、
ASSUME CS:CODE
CODE SEGMENT
START: MOV AX,CS
MOV DS,AX
MOV SI,OFFSET DISPLAYS
MOV AX,0
MOV ES,AX
MOV DI,7E00H
MOV CX,OFFSET DISPLAYEND-OFFSET DISPLAYS
CLD
REP MOVSB
MOV AX,0
MOV ES,AX
MOV WORD PTR ES:[7CH*4],7E00H
MOV WORD PTR ES:[7CH*4+2],0
MOV AX,4C00H
INT 21H
DISPLAYS: PUSH AX
PUSH ES
PUSH DX
PUSH DI
PUSH CX
MOV AX,0B800H
MOV ES,AX
DEC DH
MOV AX,160
MUL DH
MOV DI,AX
ADD DL,DL
MOV DH,0
ADD DI,DX
MOV AH,CL
MOV CH,0
S: MOV CL,[SI]
JCXZ OK
MOV AL,CL
MOV ES:[DI],AX
INC SI
ADD DI,2
JMP SHORT S
OK:
POP CX
POP DI
POP DX
POP ES
POP AX
IRET
DISPLAYEND: NOP
CODE ENDS
END START
2、
ASSUME CS:CODE
CODE SEGMENT
START: MOV AX,CS
MOV DS,AX
MOV SI,OFFSET CAPITAL
MOV AX,0
MOV ES,AX
MOV DI,7E00H
MOV CX,OFFSET CAPITALEND-OFFSET CAPITAL
CLD
REP MOVSB
MOV AX,0
MOV ES,AX
MOV WORD PTR ES:[7CH*4],7E00H
MOV WORD PTR ES:[7CH*4+2],0
MOV AX,4C00H
INT 21H
CAPITAL: PUSH BP
MOV BP,SP
DEC CX
JCXZ OK
ADD [BP+2],BX
OK:
POP BP
IRET
CAPITALEND: NOP
CODE ENDS
END START
3、
ASSUME CS:CODE
CODE SEGMENT
S1: DB 'Good,better,best,','$'
S2: DB 'Never let it rest,','$'
S3: DB 'Till good is better,','$'
S4: DB 'And bettet,best.','$'
S: DW OFFSET S1,OFFSET S2,OFFSET S3,OFFSET S4
ROW: DB 2,4,6,8
START: MOV AX,CS
MOV DS,AX
MOV BX,OFFSET S
MOV SI,OFFSET ROW
MOV CX,4
OK:
MOV BH,0
MOV DH,[SI]
MOV DL,0
MOV AH,2
INT 10H
MOV DX,[BX]
MOV AH,9
INT 21H
INC SI
ADD BX,2
LOOP OK
MOV AX,4C00H
INT 21H
CODE ENDS
END START
实验14
ASSUME CS:CODE
CODE SEGMENT
S1: DB 'nn/yy/rr ss:ff:mm','$'
ROW: DB 9,8,7,4,2,0
START: MOV AX,CS
MOV DS,AX
MOV BX,OFFSET ROW
MOV SI,OFFSET S1
MOV CX,6
S:
PUSH CX
MOV AL,[BX]
OUT 70H,AL
IN AL,71H
MOV AH,AL
MOV CL,4
SHR AH,CL
AND AL,00001111B
ADD AH,30H
ADD AL,30H
MOV [SI],AH
MOV [SI+1],AL
INC BX
ADD SI,3
POP CX
LOOP S
MOV AH,2
MOV BH,0
MOV DH,9
MOV DL,20
INT 10H
MOV DX,OFFSET S1
MOV AH,9
INT 21H
MOV AX,4C00H
INT 21H
CODE ENDS
END START
实验15
ASSUME CS:CODE
CODE SEGMENT
START: MOV AX,CS
MOV DS,AX
MOV SI,OFFSET INT9
MOV AX,0
MOV ES,AX
MOV DI,204H
MOV CX,OFFSET INT9END-OFFSET INT9
CLD
REP MOVSB
MOV AX,0
MOV ES,AX
PUSH ES:[9*4]
POP ES:[200H]
PUSH ES:[9*4+2]
POP ES:[202H]
MOV WORD PTR ES:[9*4],204H
MOV WORD PTR ES:[9*4+2],0
MOV AX,4C00H
INT 21H
INT9: PUSH AX
PUSH ES
PUSH CX
PUSH DI
IN AL,60H
PUSHF
CALL DWORD PTR CS:[200H]
CMP AL,1EH+80H
JNE OK
MOV AX,0B800H
MOV ES,AX
MOV DI,0
MOV CX,2000
S:
MOV BYTE PTR ES:[DI],'A'
ADD DI,2
LOOP S
OK: POP DI
POP CX
POP ES
POP AX
IRET
INT9END: NOP
CODE ENDS
END START
实验16
ASSUME CS:CODE
CODE SEGMENT
START: MOV AX,CS
MOV DS,AX
MOV SI,OFFSET INT7CH
MOV AX,0
MOV ES,AX
MOV DI,7E00H
MOV CX,OFFSET INT7CHEND-OFFSET INT7CH
CLD
REP MOVSB
MOV AX,0
MOV ES,AX
CLI
MOV WORD PTR ES:[7CH*4],7E00H
MOV WORD PTR ES:[7CH*4+2],0
STI
MOV AH,0
MOV AL,9
INT 7CH
MOV AX,4C00H
INT 21H
;ORG 7E00H
;后面的偏移地址从7E00H开始
INT7CH: JMP SHORT SHOW
TABLE DW OFFSET SUB1-OFFSET INT7CH+7E00H
DW OFFSET SUB2-OFFSET INT7CH+7E00H ;直接计算出偏移地址或用上面的ORG伪指令
DW OFFSET SUB3-OFFSET INT7CH+7E00H
DW OFFSET SUB4-OFFSET INT7CH+7E00H
SHOW:
PUSH BX
CMP AH,3
JA SRET
MOV BX,0
MOV ES,BX
MOV BL,AH
ADD BX,BX
ADD BX,OFFSET TABLE-OFFSET INT7CH +7E00H
CALL WORD PTR ES:[BX]
SRET: POP BX
IRET
SUB1: PUSH ES
PUSH BX
PUSH CX
MOV BX,0B800H
MOV ES,BX
MOV BX,0
MOV CX,2000
S: MOV BYTE PTR ES:[BX],' '
ADD BX,2
LOOP S
POP CX
POP BX
POP ES
RET
SUB2: PUSH ES
PUSH BX
PUSH CX
MOV BX,0B800H
MOV ES,BX
MOV BX,1
MOV CX,2000
S1:
AND BYTE PTR ES:[BX],11111000B
OR ES:[BX],AL
ADD BX,2
LOOP S1
POP CX
POP BX
POP ES
RET
SUB3: PUSH BX
PUSH ES
PUSH CX
MOV CL,4
SHL AL,CL
MOV BX,0B800H
MOV ES,BX
MOV BX,1
MOV CX,2000
S2: AND BYTE PTR ES:[BX],10001111B
OR ES:[BX],AL
ADD BX,2
LOOP S2
POP CX
POP ES
POP BX
RET
SUB4:
PUSH DS
PUSH ES
PUSH DI
PUSH SI
PUSH CX
MOV SI,0B800H
MOV DS,SI
MOV ES,SI
MOV DI,0
MOV SI,160
CLD
MOV CX,24
S3:
PUSH CX
MOV CX,160
REP MOVSB
POP CX
LOOP S3
MOV SI,0
MOV CX,80
S4:
MOV BYTE PTR [160*24+SI],' '
ADD DI,2
LOOP S4
POP CX
POP SI
POP DI
POP ES
POP DS
RET
INT7CHEND: NOP
CODE ENDS
END START
实验17
ASSUME CS:CODE
CODE SEGMENT
START: MOV AX,CS
MOV DS,AX
MOV SI,OFFSET INT7CH
MOV AX,0
MOV ES,AX
MOV DI,7E00H
MOV CX,OFFSET INT7CEND-OFFSET INT7CH
CLD
REP MOVSB
MOV AX,0
MOV ES,AX
CLI
MOV WORD PTR ES:[7CH*4],7E00H
MOV WORD PTR ES:[7CH*4+2],0
STI
MOV BX,0
MOV ES,BX
MOV BX,200H
MOV AH,0
MOV DX,1439
INT 7CH
MOV AX,4C00H
INT 21H
INT7CH: JMP SHORT SHOW
TABLE DW OFFSET INPUTS-OFFSET INT7CH +7E00H
DW OFFSET OUTPUTS-OFFSET INT7CH +7E00H
SHOW: PUSH BX
CMP AH,1
JA SRET
CMP DX,2879
JA SRET
MOV BX,0
MOV ES,BX
MOV BL,AH
ADD BX,BX
ADD BX,OFFSET TABLE-OFFSET INT7CH+7E00H
CALL WORD PTR ES:[BX]
SRET: POP BX
IRET
INPUTS: PUSH DX
PUSH AX
PUSH BX
PUSH CX
MOV AX,DX
MOV BX,1440
MOV DX,0
DIV BX
MOV CX,AX
MOV AX,DX
MOV BL,18
MOV DX,0
DIV BL
MOV DH,CL
MOV CH,AL
MOV CL,AH
INC CL
MOV AL,1
MOV AH,2
INT 13H
POP CX
POP BX
POP AX
POP DX
RET
OUTPUTS: PUSH DX
PUSH AX
PUSH BX
PUSH CX
MOV AX,DX
MOV BX,1440
MOV DX,0
DIV BX
MOV CX,AX
MOV AX,DX
MOV BL,18
MOV DX,0
DIV BL
MOV DH,CL
MOV CH,AL
MOV CL,AH
INC CL
MOV AL,1
MOV AH,3
INT 13H
POP CX
POP BX
POP AX
POP DX
RET
INT7CEND:NOP
CODE ENDS
END START