汇编习题求解

请前辈们在帮助解答时能作一些注释和解说,小弟刚学汇编,希望从大大们的帮助中学一些东西.

1.有一个地址为array的20个字的数组,说明下列程序段的功能
mov cx,20
mov ax,0
mov si,ax
som_loop:add ax,array(si)
add si,2
loop sum_loop
mov total,ax
是不是求20个偶数的和,我不是很懂,请知道的补充说明一下

2.已知ax,bx存放的是4位压缩bcd表示的十进制数,请说明如下子程序的功能和出口参数.
add al,bl
daa
xchg al,ah
adc al,bh
daa
xchg al,ah
ret

3.已知用于led数码管显示的代码表为:
ledtable db 0c0h,0fgh 0a4h,0b0h,99h,92h,82h,0f8h
db 80h,90h,88h,83h,0cgb,0c1h,86h,8eh
它依次表示0-9,a-f这16个数码的显示代码,现编写一个程序实现将lednum中的一个数字(0-9,a-f)转换成对应的led显示代码.

4.编写程序,要求从键盘接收一个数belln(0-9),然后响铃belln次.

5.写一个子程序,根据人口参数al=0//1/2,分别实现对大写字母转换成小写,小写转换成大写或大小写字母互换.欲转换的字符串在string中,用0表示结束.

6.设有一个数组存放学生的成绩(0-100),编制一个子程序统计0-59分,60-69分,70-79分,80-89分,90-100分的人数,并分别存放到scoree,scored,scorec,scoreb,scorea单元中,编写一个主程序与之配合作用.

1.有一个地址为array的20个字的数组,说明下列程序段的功能
mov cx,20
mov ax,0
mov si,ax
som_loop:add ax,array(si)
add si,2
loop sum_loop
mov total,ax
答:将array处的20个数(单位是字)相加,结果保存到total

2.已知ax,bx存放的是4位压缩bcd表示的十进制数,请说明如下子程序的功能和出口参数.
add al,bl
daa
xchg al,ah
adc al,bh
daa
xchg al,ah
ret
答:题中用了高地位交换,就是将两个BCD码相加。.
3.已知用于led数码管显示的代码表为:
ledtable db 0c0h,0fgh 0a4h,0b0h,99h,92h,82h,0f8h
db 80h,90h,88h,83h,0cgb,0c1h,86h,8eh
它依次表示0-9,a-f这16个数码的显示代码,现编写一个程序实现将lednum中的一个数字(0-9,a-f)转换成对应的led显示代码.
答:程序如下
stack segment stack
db 100h dup(?)
stack ends

data segment
ledtable db 0c0h,0f9h,0a4h,0b0h,99h,92h,82h,0f8h
db 80h,90h,88h,83h,0c6h,0c1h,86h,8eh
lednum db 3
data ends

code segment 'code'
assume cs:code,ss:stack,ds:data
start:
mov ax,data
mov ds,ax

lea bx,ledtable
mov al,lednum
xlat

mov ax,4c00h
int 21h
code ends
end start

4.编写程序,要求从键盘接收一个数belln(0-9),然后响铃belln次
答:程序如下
.model small
.stack
.data
str1 db 'bellN=?(0-9)',0dh,0ah,'$'
str2 db 'Over!',0dh,0ah,'$'
.code
.startup
mov dx,offset str1
mov ah,09h
int 21h
xor cx,cx
mov ah,01h
int 21h
mov cl,al
sub cl,30h ;把asc转换为十进制数字
again: mov dl,07h ;响铃
mov ah,02h
int 21h
call delay
loop again
jmp done
delay: mov dx,0ffffh ;延时
mov ax,0
delay1: sub ax,5
sbb dx,0
jnz delay1
ret ;返回again
done: mov dx,offset str2
mov ah,09h
int 21h
.exit 0
end

5.写一个子程序,根据人口参数al=0//1/2,分别实现对大写字母转换成小写,小写转换成大写或大小写字母互换.欲转换的字符串在string中,用0表示结束
答:程序如下
convert proc
mov ebx, 1
cmp al, 0
jne next
;大写变小写
A1: mov bl, string[ebx]
inc ebx
cmp bl, 41h
jb A1
cmp bl, 5ah
ja A1
xor bl, 20h
mov string[ebx],bl
cmp bl, 20h
jz endpro
jmp A1
next:
cmp al, 1
jne next1
;小写变大写
A2: mov bl, string[ebx]
inc ebx
cmp bl, 61h
jb A2
cmp bl, 7ah
ja A2
xor bl, 20h
mov string[ebx],bl
cmp bl, 20h
jz endpro
jmp A2
next1:
cmp al, 2
jne endpro
;大小写互换
A3: mov bl, string[ebx]
inc ebx
cmp bl, 41h
jb A3
cmp bl, 5ah
jbe c1
cmp bl, 61h
jb A3
cmp bl, 7ah
ja A3
C1: xor bl, 20h
mov string[ebx],bl
cmp bl, 20h
jz endpro
jmp A2
endpro:
ret
convert endp

6.设有一个数组存放学生的成绩(0-100),编制一个子程序统计0-59分,60-69分,70-79分,80-89分,90-100分的人数,并分别存放到scoree,scored,scorec,scoreb,scorea单元中,编写一个主程序与之配合作用.
.model flat, stdcall
.data
array byte 80 dup(?)
scoreE byte 0
scoreD byte 0
scoreC byte 0
scoreB byte 0
scoreA byte 0
.code
start:
mov ebx, offset array
xor ecx, ecx
again:
ReadSDecByte al
cmp al, -1
je contine
mov [ebx], al
inc ecx
jmp again
mov ebx, offset array
agagin1:
cmp [ebx], 59
jbe L1
cmp [ebx], 69
jbe L2
cmp [ebx], 79
jbe L3
cmp [ebx], 89
jbe L4
L1: inc scoreE
jmp ebdpro
L2: inc scoreD
jmp ebdpro
L3: inc scoreC
jmp ebdpro
L2: inc scoreB
jmp ebdpro
inc scoreA
ret
end start
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-11-13
第1:mov cx,20
mov ax,0
mov si,ax
som_loop:add ax,array【si】
add si,2
loop sum_loop
mov total,ax ;此句不对,寄存器应该赋给寄存器而不是常量
此题是求数组中偶数的和
其他题另请高人了
第2个回答  2008-11-12
1:求array单元20个数的和
因为字占两个单元,所以si加了2
2:就是将两个BCD码相加。题中用了高地位交换,我想是障眼法吧

6:LOOP0:MOV AL , [SI]

CMP AL,60
JA LOOP1
MOV scoree,AL
LOOP1: CMP AL,70
JA LOOP2
MOV SCORED

LOOP2:CMP AL,80
JA LOOP3
MOV SCOREC,AL

LOOP3:CMP AL,90
JA LOOP4
MOV SCORED

LOOP3: INC SI
DEC CX
JNZ LOOP0

后面的题目我也不是很会,我也是初学者!!!
相似回答