CMP AH, AL JAE LOOP1 XCHG AH, AL LOOP2 INC BX
CMP AH, [BX] JAE LIS XCHG AH, [BX] JMP LOP2 LIS: CMP AL , [BX] JBE LOP2 XCHG AL, [BX] LOOP2
MOV MAX, AH MOV MIN, AL RET START ENDP CODE_SEG ENDS
END START 4.10 给出等值语句如下: ALPHA BETA
EQU EQU
100 25
GAMMA EQU 2
下列表达式的值是多少? ⑴ ALPHA*100+BETA ⑶ (ALPHA+2)*BETA-2
⑵ ALPHA MOD GAMMA+BETA
⑷ (BETA/3) MOD 5
⑸ (ALPHA+3)*(BETA MOD GAMMA) ⑹ ALPHA GE GAMMA ⑺ BETA AND 7 ⑻ GAMMA OR 3 【解】: ⑴ ALPHA*100+BETA 100×10025=10025
⑵ ALPHA
MOD GAMMA+BETA
100/(25+2)=19
⑶ (ALPHA+2)*BETA-2 (100+2)*25=2548 ⑷ (BETA/3)
MOD 5
(25/3) MOD 5=3
⑸ (ALPHA+3)*(BETA MOD GAMMA) (100+3)*(25 MOD 2)=103 ⑹ ALPHA GE GAMMA 100 GZ GAMMA=0FFFFH
16
⑺ BETA AND 7 25 AND 7=1 ⑻ GAMMA OR 3
2 OR 3=3
4.9 对于下面的数据定义,三条MOV指令分别汇编成什么?(可用立即数方式表示) TABLEA DW TABLEB DB TABLEC DB
┇ MOV MOV
AX,LENGTH TABLEA BL,LENGTH TABLEB
10 DUP(?) 10 DUP(?) ’1234’
MOV CL,LENGTH TABLEC 【解】: MOV AX,LENGTH TABLEA MOV AX, OOOAH
MOV
BL,LENGTH TABLEB MOV BL, 0AH
MOV CL,LENGTH TABLEC MOV CL, O1H
4.10 对于下面的数据定义,各条MOV指令单独执行后,有关寄存器的内容是什么? FLDB DB ? TABLEA DW 20 DUP(?) TABLEB DB
‘ABCD’
⑵ MOV AX,TYPE TABLEA ⑷ MOV DX,SIZE TABLEA
⑴ MOV AX,TYPE FLDB ⑶ MOV CX,LENGTH TABLEA
⑸ MOV CX,LENGTH TABLEB 【解】:(1) MOV AX,TYPE FLDB (AX)= 1 (2) MOV AX,TYPE TABLEA (AX)= 2 (3) MOV CX,LENGTH TABLEA (CX)= 20 (4) MOV DX,SIZE TABLEA (DX)= 40 (5) MOV CX,LENGTH TABLEB (CX)= 1
17
习题 5
5.1编写程序,从键盘接收一个小写字母,然后找出它的前导字符和后续字符,再按顺序用大写字母显示这三个字符。 【解】:MAIN PROC FAR
start:
push ds sub ax,ax push ax
input: mov ah,7H int 21H cmpe:
cmp al,20H JE exit
cmp al,61H JL input
cmp al,7AH JG input print: sub al,01H mov dl,al mov ah,02H int 21H
add al,01H mov dl,al mov ah,02H int 21H
add al,01H mov dl,al mov ah,02H int 21H
18
;输出换行回车 mov dl,0AH mov ah,02H int 21H
jmp input exit : ret MAIN ENDP END start
5.2 将AX寄存器中的16位数分成4组,每组4位,然后把这4组数分别放在AL、BL、CL和DL中。 【解】:DB 4 dup(?)
.stack 100H
.code
MAIN PROC FAR start: push ds and ax,00H push ax
mov ax,1234H
mov cx,04H mov si,00H lop: push cx mov cl,04H rol ax,cl
push ax and al,0FH
mov BYTE PTR x[si],al pop ax pop cx add si,2 Loop lop mov al,[X] mov bl,[X+2]
19
mov cl,[X+4] mov dl,[X+6] print: mov ah,02H int 21H
mov dl,al mov ah,02H int 21H
mov dl,bl mov ah,02H int 21H
mov dl,cl mov ah,02H int 21H exit: ret MAIN ENDP END start
5.3 试编写一程序,要求比较两个字符串STRING1和STRING2所含字符是否相同,若相同则显示MATCH,若不相同则显示NO MATCH。 【解】:data segment
string1 db \ string2 db \
inf1 db \ inf2 db \data ends code segment
main proc far
assume ds:data,cs:code,es:code start: push ds mov ax,0 push ax mov ax,data mov ds,ax mov es,ax lea si,string1
20