当前位置:文档之家› 微机原理及汇编语言作业 编程

微机原理及汇编语言作业 编程

第五大组题
5.一个32位数存放在以数据段的BUF单元开始的位置。

编写子程序统计该数中含“1”的个数,并将其结果存入RSLT字节单元。

stac segment stack
db 1024 dup(0)
stac ends
data segment
RSLT db 00H ;使rslt初值为零
buf dd 12345678h ;定义buf
data ends
code segment 'code'
assume cs:code,ds:data,ss:stac
start: mov ax,data
mov ds,ax
mov cl ,32
call again ;调用子程序
mov ax ,4c00h
int 21h
gain proc ;定义过程
shr word ptr ds:[si+2],1 ;最高字逻辑右移一位,D16进入CF
rcr word ptr ds:[si+0],1 ;CF移入D15,最低字右移一位进入CF
nc L1
inc RSLT
L1:again endp
code ends
end start
55.在0200H单元中有一个数x,利用移位和相加的办法,使x×10(假定x×10>255)后送回原单元。

stac segment stack
db 1024 dup(0)
stac ends
data segment
org 0200h ;将变量x的定位在0200h处
x db 56h
data ends
code segment 'code'
assume cs:code,ds:data,ss:stac
start: mov ax,data
mov ds,ax
mov al,x ;把x放到al中
+ xor ah,ah ;使AH=0,同时使CF=0
shl ax,1 ;AX=AL*2
mov bx,ax ;BX=AX=AL*2
shl ax,1 ;AX=AL*4
shl ax,1 ;AX=AL*4
add ax,bx
mov x,al ;将ax中低八位放到x中
mov x+1,ah ;将ax中高八位放到x+1中
mov ax, 4c00h
int 21h
code e nds
end start
75.编写子程序。

将AL中的二进制数转换成对应的ASCII码(置于AL中)返回。

主程序调用子程序实现上述功能。

.model small
.stack
.data
.code
start: mov ax,@data
mov ds,ax
mov al,28h
call label1 ;调用子程序
mov ax,4c00h
int 21h
label1 proc
and al,0fh ;只取al的低四位
or al,30h ;al高四位变成3(0~9的ASCII码是30h~39h)
cmp al,39h ;是0~9还是0A~0Fh(A~F的ASCII的值是41h~46h)
jbe htoend ;小于等于39h,al低4位的数值在0~9之间
add al,7 ;数值在0A~0F间,其ASCII码值还要加上7 htoend: ret ;子程序返回
label1 endp ;过程结束
end start。

相关主题