编辑: 飞翔的荷兰人 | 2014-09-06 |
第五章答案 2006-11-04 22:01 清华大学出版社,沈美明、温冬婵编著 现在部分学校用的还是这本书,清华大学出版社,沈美明、温冬婵编著.
?? 这当然不是标准答案,自己做的,呵呵,希望对大家有用处. 5.1 试编写一个汇编语言程序,要求对键盘输入的小写字母用大写字母显示出来 .model small .stack 100H .code main proc far Start: ?push dx ?mov ax,0 ?push ax ? ?mov ah,01H ?int 21H ? ?cmp al,61H ? ?jl lop1 ? ?cmp al,7BH ?jge lop1 ? ?sub al,20H ?mov dl,al ? ?lop1:mov ah,2 ?int 21H ? ?ret End start 5.2 编写一个程序,从键盘接受一个小写字母,然后找出它的前导字符和后续字符,再按顺序显示这三个字符. .model small .386 .code 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 ? ?;
输出换行回车 ?mov dl,0AH ?mov ah,02H ?int 21H ?jmp input exit : ?ret MAIN ENDP END start 5.3 将AX寄存器中的16位数分成4组,每组4位,然后把这四组数分别放在AL、BL、CL、DL中. .model small .data x 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] ?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.4 编写一个程序,要求比较两个字符串STRING1和STRING2所含字符是否相同,若相同则显示 MATCH ,若不同在显示: NO MATCH . .model small .data STRING1 DB '
I must study hard'
STRING2 DB '
I must study hard'
X?????? DB '
MATCH .$'
Y?????? DB '
NO MATCH.$'
.stack 100H .code main proc far Start: ?push dx ?mov ax,0 ?push ax ? ?mov ax,@data ?mov ds,ax ?mov es,ax ? ?lea si,STRING1 ?lea di,STRING2 ?cld ? ?mov cx,(string2-string1)/ type STRING2 ?ret End start 5.5编写一个程序,要求能从键盘接收一个个位数N,然后响铃N次,(响铃的ASCII为07). 这题比较有意思,呵呵. model small .code main proc far start: ?push ds ?sub ax,ax ?push ax input: mov ah,01H int 21H cmp al,20H je? exit cmp al,30H jle input cmp al,3AH jge input sub al,30H mov cx,ax and cx,0FFH lop: mov dl,07H mov ah,2H int 21H loop lop jmp input exit : ret main endp end start 5.6编写程序,将一个包含有20个数据的数组M分成两个数组:正数数组和负数数组N,并分别把这两个数组中的数据个数显示出来. .model small .386 .data M DB 1,2,3,4,5,6,7,8,9,10,-1,-2,-3,-4,-5,-6,-7,-8,-9,-10 P DB
20 dup(?) N DB
20 dup(?) .code MAIN PROC FAR start: ??PUSH ds ??AND? ax,0 ??PUSH ax ?? ??MOV? ax,@data ??mov? ds,ax ??MOV? bx,0 ??MOV? si,0 ??MOV? di,0 ??MOV? cx,20D ?? cmpe? : ??CMP? M[bx],0 ??JL? ifLow hight : ??MOV? al,byte ptr M[bx] ??MOV? byte ptr P[si],al ??inc? si ??JMP? commonContrl ifLow : ??MOV? al,byte ptr M[bx] ??MOV? byte ptr N[di],al ??INC? di commonContrl: ??INC? bx ??loop cmpe ??mov? ax,si ??call showNumber ??call printCR ??mov? ax,di ??call showNumber exit:?ret MAIN ENDP 注意,ShowNumber这个子过程有问题,请自行修改;
showNumber PROC NEAR covernum: ??DAA ??MOV? dx,ax ??MOV? cl,2H show: ??ROL? dl,4H ??push dx ??AND? dl,0fH ??ADD? dl,30H ??MOV? ah,02H ??int? 21H ??pop? dx ??loop show ??ret showNumber ENDP printCR PROC NEAR ??mov dl,0aH ??mov ah,02H ??int 21H ??mov dl,0dH ??mov ah,02H ??int 21H ??ret printCR ENDP end start 5.7编制一个汇编语言程序,求出首地址为DATA的100D字数组中的最小偶数,并把它放在AX中. ???? 此题根据题意要求应该使用完整汇编格式,因为精简格式也使用DATA.... dataare segment DATA DW 3322H,4555H,200H,3544H,1245H num? DB ($-DATA)/2 dataare ends code segment assume cs:code,ds:dataare MAIN PROC FAR start: ??push ds ??mov? ax,0H ??push ax ?? ??mov? ax,dataare ??mov? ds,ax ??mov? dx,0H?偶数数量计数 ??mov? cx,Word ptr [num] ??mov? si,0H isO: ??mov? bx,WORD PTR DATA[si] ??shr? bx,1H ??jnc? addDX ??jmp? commonControl addDX: ??ADD? dx,1H ??cmp? dx,1H ??je?? firstAXValue compare: ??mov? bx,WORD PTR DATA[si] ??cmp? bx,ax ??jge? commonControl ??mov? ax,bx commonControl: ??ADD? si,2H ??loop isO ??jmp? exit firstAXvalue: ??mov ax,WORD PTR DATA[si] ??jmp compare exit: ??ret MAIN ENDP code ends END start 5.8没有做.. 5.9编写一个汇编语言程序,要求从键盘上接收一个思维的十六位进制数,并在终端上显示与它等值的二进制数. .model small .386 .code main proc far start: ?push ds ?mov? ax,0 ?push ax? ?mov? ax,0 ?mov? cx,4 ?mov? dx,0 input: ?mov? ah,1H ?int? 21H ?cmp? al,30H ?jl?? input ??? cmp? al,39H ??? jle? s ?cmp? al,61H ?jl?? input ?cmp? al,66H ?jg?? input ?sub? al,27H s: ?sub? al,30H ?add? dl,al ?cmp? cx,1H ?je?? f ?rol? dx,4 ? f: ?loop input exit: ?call print ?ret main endp print proc near ?mov cx,10H p: rol? dx,1 ?push dx ?and? dx,1 ?add? dx,30H ?mov? ah,2 ?int? 21H ?pop? dx ?loop p ret print endp end start ? 5.10设有一段英文,其变量字符名为ENG,并以$字符结束.试编写一程序,查对单词SUN在该文中的出现次数,并以格式 SUN XXXX 显示出次数. .model small .386 .data ?ENG???? db '