首页 > 代码库 > 汇编大题
汇编大题
1.用主,子程序结构编写一个程序,计算sun = 1!+2!+3!+4!+5!
答案:
; 数据段
data segment
sum dw 0
data ends
;程序段
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
xor ax,ax
xor cx,cx
mov cl,5
xunhuan1:
call fact
add sum,ax
loop xuanhuan1
mov ah,4ch
int 21h;
fact proc
push cx;
xor ax,ax
mov al,1
xunhuan 2:
pop cxmul al,cl
loop xunhuan2
ret
fact endp
code ends
end start
2 .将一个给定的二进制数按位转换成相应的ascII码字符串,送到指定的存储单元并显示,如二进制数1001 0011 转换成字符串‘1001 0011’。要求将转换过程写成子程序,
并且子程序应具有较好的通用性,而且必须能实现对8位和16位二进制数的转换。
答案:
data segment
num8 db 93h
num16 dw 0abcdh
ascbuf db 20 dup (0)
data ends
code segment
assume ds:data,cs:code,ss:stack
start:
mov ax,data
mov ds,ax
xor dx,dx
mov dl,num8
mov cx,8
lea di,ascbuf
call fact
mov [di],byte ptr odh
mov [di+1],byte ptr 0ah
mov [di+2],byte ptr ‘$‘
lea dx,ascbuf
mov ah,09h
int 21h
mov dx,num16
mov cx,16
lea di,ascbuf
call fact
mov [di],byte ptr 0dh
mov [di+1],byte ptr 0ah;
mov [di+2],byte ptr ‘$‘
lea dx,ascii
mov ah,09h
int 21h
fact proc
push axcmp cx,8jne L1mov dh,dlL1:
pop axxor al,alrol dx,1rcl al,1add al,30hmov [di],alinc diloop L1
ret
fact endp
code ends
end start
3.用存储单元传送参数,编写一个子程序,将二位十六进制数转换为对应的ascII码,并说明主程序是如何调用这个子程序的。
答案:
data segment
data endshexdata db ?
ascdata db 2 dup (?)
code segment
assume cs:code,ds:data,ss:stack
start:
mov ax,data
mov ds,ax
mov hexdata,xxx
call fact
fact proc
push cx
mov ch,hexdata
and ch,0fh
add ch,30h
cmp ch,09h
hna hex1
add ch,07h
hex1:
hex2:mov ascdata,ch
mov ch,hexdata
mov cl,4
shr ch,cl
add ch,30h
cmp ch,39h
jna hex2
add ch,07h
mov ascdata+1,cl
pop cx
ret
fact endp
code ends
end start