虽然是两道题,但解题思路几乎相同。
1、用十六进制形式将BL的内容显示在屏幕上
; 本程序通过编译,运行正确。
Code Segment
Assume CS:Code,DS:Code
; -----------------------------------------
; 功能:输出一个字符
; 入口:dl=要显示的字符
enter_Chr proc Near
push ax
mov ah,02h
int 21h
pop ax
ret
enter_Chr endp
; -----------------------------------------
; 功能:将AL中的低4位二进制数转换成ASCII码
; 入口:AL
; 出口:AL=转换后的ASCII码
AL_ASCII Proc Near
cmp al,9 ;AL>9?
ja @@Letter ;AL>9,按大写字母处理
or al,30h ;AL<=9,按数字处理
ret
@@Letter: sub al,9 ;字母,AL减9
or al,40h ;转换成相应的大写字母
ret
AL_ASCII EndP
; -----------------------------------------
; 功能:将AL中的字节数转换成ASCII码
; 入口:AL
; 出口:AX=转换后的ASCII码
Byte_ASCII Proc Near
mov cx,4
xor ah,ah ;将AH置0
shl ax,cl ;将AX左移4位
shr al,cl ;将AL右移4位
xchg ah,al
call AL_ASCII ;调用子程序,将AL中的值转换成相应的ASCII码
xchg ah,al
call AL_ASCII
xchg ah,al
ret
Byte_ASCII EndP
; -----------------------------------------
Start: push cs
pop ds
push cs
pop es ;使数据段、附加段与代码段同段
mov bl,8dh ;将8dh赋给bl(使用者可自行改成其它值。若不给bl赋初值,则bl恒等于0)
mov al,bl ;bl→al,准备调用转换子程序Byte_ASCII
call Byte_ASCII
mov dl,al ;al→dl,准备调用显示字符子程序enter_Chr
call enter_Chr ;显示一个字符
mov dl,ah ;ah→dl,准备调用显示字符子程序enter_Chr
call enter_Chr
mov dl,'H' ;'H'→dl,准备调用显示字符子程序enter_Chr
call enter_Chr
Exit_Proc: mov ah,4ch ;结束程序
int 21h
Code ENDS
END Start ;编译到此结束
2、把内存中BUF1开始100个单元组合BCD码转换为ACSⅡ码,放在BUF2开始的100个单元内。
; 本程序通过编译,运行正确。
Code Segment
Assume CS:Code,DS:Code
; -----------------------------------------
; 功能:将AL中的低4位二进制数转换成ASCII码
; 入口:AL
; 出口:AL=转换后的ASCII码
AL_ASCII Proc Near
cmp al,9 ;AL>9?
ja @@Letter ;AL>9,按大写字母处理
or al,30h ;AL<=9,按数字处理
ret
@@Letter: sub al,9 ;字母,AL减9
or al,40h ;转换成相应的大写字母
ret
AL_ASCII EndP
; -----------------------------------------
; 功能:将AL中的字节数转换成ASCII码
; 入口:AL
; 出口:AX=转换后的ASCII码
Byte_ASCII Proc Near
push cx
mov cx,4
xor ah,ah ;将AH置0
shl ax,cl ;将AX左移4位
shr al,cl ;将AL右移4位
xchg ah,al
call AL_ASCII ;调用子程序,将AL中的值转换成相应的ASCII码
xchg ah,al
call AL_ASCII
xchg ah,al
pop cx
ret
Byte_ASCII EndP
; -----------------------------------------
BUF1 db 100 dup(?) ;这100个单元是字节变量
BUF2 dw 100 dup(?) ;这100个单元是字(双字节)变量
Start: push cs
pop ds
push cs
pop es ;使数据段、附加段与代码段同段
; 给数组变量BUF1赋初值。否则,内存中的默认值都是0。
cld
lea di,BUF1
mov cx,10
xor ah,ah
Make_BCD1: push cx
mov cx,10
mov al,9
Make_BCD2: push ax
push cx
mov cx,4
shl al,cl
pop cx
or al,ah
stosb
pop ax
dec al
loop Make_BCD2
pop cx
inc ah
loop Make_BCD1
lea si,BUF1
lea di,BUF2
mov cx,100
BCD_ASCII: lodsb
call Byte_ASCII
stosw
loop BCD_ASCII
Exit_Proc: mov ah,4ch ;结束程序
int 21h
Code ENDS
END Start ;编译到此结束
-R
AX=0000 BX=0000 CX=018F DX=0000 SP=0000 BP=0000 SI=0000 DI=0000
DS=0B32 ES=0B32 SS=0B42 CS=0B42 IP=0150 NV UP EI PL NZ NA PO NC
0B42:0150 0E PUSH CS
-
-G155
AX=0000 BX=0000 CX=018F DX=0000 SP=0000 BP=0000 SI=0000 DI=0000
DS=0B42 ES=0B42 SS=0B42 CS=0B42 IP=0155 NV UP EI PL NZ NA PO NC
0B42:0155 8D3E2400 LEA DI,[0024] DS:0024=0000
-
-D24 L64
0B42:0020 00 00 00 00-00 00 00 00 00 00 00 00 ............
0B42:0030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
0B42:0040 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
0B42:0050 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
0B42:0060 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
0B42:0070 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
0B42:0080 00 00 00 00 00 00 00 00 ........
-
-D88 LC8
0B42:0080 00 00 00 00 00 00 00 00 ........
0B42:0090 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
0B42:00A0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
0B42:00B0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
0B42:00C0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
0B42:00D0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
0B42:00E0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
0B42:00F0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
0B42:0100 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
0B42:0110 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
0B42:0120 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
0B42:0130 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
0B42:0140 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
-
-G179
AX=0AFF BX=0000 CX=0000 DX=0000 SP=0000 BP=0000 SI=0000 DI=0088
DS=0B42 ES=0B42 SS=0B42 CS=0B42 IP=0179 NV UP EI PL NZ NA PE NC
0B42:0179 8D362400 LEA SI,[0024] DS:0024=8090
-
-D24 L64
0B42:0020 90 80 70 60-50 40 30 20 10 00 91 81 ..p`P@0 ....
0B42:0030 71 61 51 41 31 21 11 01-92 82 72 62 52 42 32 22 qaQA1!....rbRB2"
0B42:0040 12 02 93 83 73 63 53 43-33 23 13 03 94 84 74 64 ....scSC3#....td
0B42:0050 54 44 34 24 14 04 95 85-75 65 55 45 35 25 15 05 TD4$....ueUE5%..
0B42:0060 96 86 76 66 56 46 36 26-16 06 97 87 77 67 57 47 ..vfVF6&....wgWG
0B42:0070 37 27 17 07 98 88 78 68-58 48 38 28 18 08 99 89 7'....xhXH8(....
0B42:0080 79 69 59 49 39 29 19 09 yiYI9)..
-
-G18B
AX=3930 BX=0000 CX=0000 DX=0000 SP=0000 BP=0000 SI=0088 DI=0150
DS=0B42 ES=0B42 SS=0B42 CS=0B42 IP=018B NV UP EI PL NZ NA PE NC
0B42:018B B44C MOV AH,4C
-
-D88 LC8
0B42:0080 39 30 38 30 37 30 36 30 90807060
0B42:0090 35 30 34 30 33 30 32 30-31 30 30 30 39 31 38 31 5040302010009181
0B42:00A0 37 31 36 31 35 31 34 31-33 31 32 31 31 31 30 31 7161514131211101
0B42:00B0 39 32 38 32 37 32 36 32-35 32 34 32 33 32 32 32 9282726252423222
0B42:00C0 31 32 30 32 39 33 38 33-37 33 36 33 35 33 34 33 1202938373635343
0B42:00D0 33 33 32 33 31 33 30 33-39 34 38 34 37 34 36 34 3323130394847464
0B42:00E0 35 34 34 34 33 34 32 34-31 34 30 34 39 35 38 35 5444342414049585
0B42:00F0 37 35 36 35 35 35 34 35-33 35 32 35 31 35 30 35 7565554535251505
0B42:0100 39 36 38 36 37 36 36 36-35 36 34 36 33 36 32 36 9686766656463626
0B42:0110 31 36 30 36 39 37 38 37-37 37 36 37 35 37 34 37 1606978777675747
0B42:0120 33 37 32 37 31 37 30 37-39 38 38 38 37 38 36 38 3727170798887868
0B42:0130 35 38 34 38 33 38 32 38-31 38 30 38 39 39 38 39 5848382818089989
0B42:0140 37 39 36 39 35 39 34 39-33 39 32 39 31 39 30 39 7969594939291909
-
-Q
温馨提示:内容为网友见解,仅供参考