汇编语言作业答案讲解.docx

上传人:b****5 文档编号:28783611 上传时间:2023-07-19 格式:DOCX 页数:24 大小:1.21MB
下载 相关 举报
汇编语言作业答案讲解.docx_第1页
第1页 / 共24页
汇编语言作业答案讲解.docx_第2页
第2页 / 共24页
汇编语言作业答案讲解.docx_第3页
第3页 / 共24页
汇编语言作业答案讲解.docx_第4页
第4页 / 共24页
汇编语言作业答案讲解.docx_第5页
第5页 / 共24页
点击查看更多>>
下载资源
资源描述

汇编语言作业答案讲解.docx

《汇编语言作业答案讲解.docx》由会员分享,可在线阅读,更多相关《汇编语言作业答案讲解.docx(24页珍藏版)》请在冰豆网上搜索。

汇编语言作业答案讲解.docx

汇编语言作业答案讲解

第一题:

源程序:

;从屏幕上输入大写字母,转换为小写字母并输出(生成.com文件)

;要求:

程序具有可读性、容错性

homework1segmentpara

assumecs:

homework1,ss:

homework1,ds:

homework1

org0100h

mainprocfar

leadx,str1

movah,09h

int21h;显示输入提示

main0:

movah,01h;输入字符

int21h

cmpal,41h;输入判断

jbmain1

cmpal,5ah

jamain1

leadx,str4;显示输入成功提示

movah,09h

int21h

addal,20h;大写字母的ASCII-->小写字母的ASCII

pushax

leadx,str2;显示输出提示

movah,09h

int21h

popax

movdl,al

movah,02h;显示小写字母

int21h

movax,4c00h;退出OS

int21h

main1:

;错误提示

leadx,str3

movah,09h

int21h

jmpmain0

mainendp

str1db0dh,0ah,'Pleaseinputabigcasecharacter:

$'

str2db0dh,0ah,'Theconvertedresultis:

$'

str3db0dh,0ah,'Thereisainputerror,pleaseinputagain!

$'

str4db0dh,0ah,'Thecharacteryouhaveinputedisright!

$'

homework1ends

endmain

运行结果:

第二题:

源程序:

;编写一子程序asc2bin,将ASCII转换为二进制数

;要求:

输入参数:

AL中存放需要转换的ASCII

;输出参数:

AL中存放转换后的二进制数并返回

datasegmentpara

vardb31h,39h,46h

bufdb3dup(0)

dataends

ss_segsegmentstack

db100dup(0)

ss_segends

codesegmentpara

assumecs:

code,ss:

ss_seg,ds:

data

mainprocfar

movax,data;数据段赋值

movds,ax

movbx,0

moval,var[bx]

callasc2bin

movbuf[bx],al

incbx

moval,var[bx]

callasc2bin

movbuf[bx],al

incbx

moval,var[bx]

callasc2bin

movbuf[bx],al

movax,4c00h

int21h

;编写一个把ASCII转换为二进制数的子程序

;入口参数:

AL中存放需要转换的ASCII

;出口参数:

AL中存放转换后的二进制数并返回

asc2binproc

subal,30h

cmpal,09h

jbemain1

subal,07h

main1:

ret

asc2binendp

mainendp

codeends

endmain

运行结果:

第三题:

源程序:

;内存中存放8个16位有符号数,求8个数值之和,并将结果存放在内存变量SUM中

;注:

程序中应用到字扩展为双字的指令CWD

datasegmentpara

bufdw12000,-14586,28965,-31596,14896,25478,32145,-26987

sumdd0

dataends

ss_segsegmentstack

dw100dup(0)

ss_segends

codesegmentpara

assumecs:

code,ss:

ss_seg,ds:

data

mainprocfar

movax,data;数据段赋值

movds,ax

movcx,8;设置循环次数

movbx,0

circle:

movax,buf[bx]

cwd;ax-->dx,ax

addwordptrsum,ax

adcwordptrsum+2,dx

addbx,2

loopcircle

movax,4c00h

int21h

mainendp

codeends

endmain

运行结果:

第四题:

源程序:

;内存中存放8个8位有符号数,请按从大到小顺序排列

datasegmentpara

bufdb-128,127,-112,123,-109,112,0,64

countequ($-buf)

dataends

ss_segsegmentstack

db100dup(0)

ss_segends

codesegmentpara

assumecs:

code,ss:

ss_seg,ds:

data

mainprocfar

movax,data;对数据段赋值

movds,ax

movcx,count-1;定义最多的外循环次数

circle2:

;外循环

movbx,0

movdx,0;设置标志

pushcx;保存外循环的CX

circle1:

;内循环

moval,buf[bx]

cmpal,buf[bx+1]

jgemain1

xchgal,buf[bx+1]

movbuf[bx],al

movdx,1

main1:

addbx,1

loopcircle1

popcx

cmpdx,0;判断标志,进一步判断是不是继续执行外循环

jzexit

loopcircle2

exit:

;退出OS

movax,4c00h

int21h

mainendp

codeends

endmain

运行结果:

第五题

源程序:

;内存中有8个16位数,请编写程序将8个数倒序排放

datasegmentpara

bufdw14785,10596,9658,-21589,0,6365,-4852,5812

dataends

ss_segsegmentstack

dw100dup(0)

ss_segends

codesegmentpara

assumecs:

code,ss:

ss_seg,ds:

data

mainprocfar

movax,data;数据段赋值

movds,ax

movcx,4;设定循环次数

movbx,0

main1:

movax,buf[bx]

movsi,14

subsi,bx

xchgax,buf[si]

movbuf[bx],ax

addbx,2

loopmain1

movax,4c00h

int21h

mainendp

codeends

endmain

运行结果:

第六题:

源程序:

;从键盘输入4位十进制数,然后以16进制形式显示在屏幕上.

;要求:

键盘输入和显示结果时均应有提示

datasegmentpara

str1db0dh,0ah,'Pleaseinputafourdecimalnumber:

$'

str2db0dh,0ah,'Thefexadecimalformofthenumberyouhaveinputedis:

$'

dataends

ss_segsegmentstack

db100dup(0)

ss_segends

codesegmentpara

assumecs:

code,ss:

ss_seg,ds:

data

mainprocfar

movax,data;数据段赋值

movds,ax

leadx,str1

movah,9

int21h;显示输入提示

movah,1;输入千位

int21h

subal,30h;得到千位数

movah,0

movbx,10

movcx,3;千位乘10的次数

circle1:

mulbx;得到千位数*1000

loopcircle1

pushax;保存得到的千位数*1000

movah,1

int21h;输入百位

subal,30h;得到百位数

movah,0

movcx,2;百位乘10的次数

circle2:

mulbx;得到千位数*1000

loopcircle2

movdx,ax;保存得到的百位数*100

popax;千位数*1000出栈

addax,dx;千位数*1000+百位数*100-->ax

pushax

movah,1

int21h;输入十位数

subal,30h;得到十位数

movah,0

mulbx;得到十位数*10

movdx,ax

popax;千位数*1000+百位数*100出栈

addax,dx;得到千位数*1000+百位数*100+十位数*10

pushax;千位数*1000+百位数*100+十位数*10-->入栈

movah,1

int21h;输入个位数

subal,30h;得到个位数

movah,0

movdx,ax

popax

addax,dx;得到千位数*1000+百位数*100+十位数*10+个位?

pushax

leadx,str2

movah,9

int21h;显示输出提示

popax

pushax

moval,ah

movcl,4

shral,cl;得到AH的高四位

callconvert;得到AH的高四位所对应的ASCII

callputchar;显示AH的高四位所对应的ASCII对应的字符

popax

pushax

moval,ah

callconvert;得到AH的低四位所对应的ASCII

callputchar;显示AH的低四位所对应的ASCII对应的字符

popax

pushax

shral,cl;得到AL的高四位

callconvert;得到Al的高四位所对应的ASCII

callputchar;显示Al的高四位所对应的ASCII对应的字符

popax

callconvert;得到Al的低四位所对应的ASCII

callputchar;显示Al档低四位所对应的ASCII对应的字符

moval,48h

callputchar;输出末尾的H

movax,4c00h

int21h;退出OS

;定义一个四位二进制数转换为一位十六进制数的子程序

;入口参数:

一个四位二进制数

;出口参数:

该四位二进制数对应的十六进制数的ASCII

convertproc

andal,0fh;取低四位

addal,30h

cmpal,39h

jbemain1

addal,07h

main1:

ret

convertendp

;定义一个显示AL中的ASCII所对应字符的子程序

;入口参数:

al

;出口参数:

显示字符

putcharproc

movah,02h

movdl,al

int21h;显示字符

ret

putcharendp

mainendp

codeends

endmain

运行结果:

第七题:

源程序:

;数据段从100H开始存放字符串str1

;从200H开始存放str2

;二者均以NULL字符为结束符

;编写程序将str2拷贝到str1末尾,形成一个完整字符串

datasegmentpara

org100h

str1db0dh,0ah,'Hello',0

org200h

str2db0dh,0ah,'Automation!

',0

dataends

ss_segsegmentstack

db100dup(0)

ss_segends

codesegmentpara

assumecs:

code,ss:

ss_seg,ds:

data

mainprocfar

movax,data;数据段赋值

movds,ax

pushds

popes;es,ds-->data

moval,0

movcx,0ffffh

leadi,str1

repnzscasb

decdi;使es:

di-->str1中的结束符

leasi,str2

incsi

incsi;使ds:

si-->str2中的有效字符开头

cld;df<--0

main2:

cmpal,str2[si];判定是否到str2的结束

jzmain3

movsb

jmpmain2;串传送

main3:

movstr1[di],0;str1末尾加0

leasi,str1

callgetchar;开始取字符

moval,0

callputchar;显示最后的0

movax,4c00h

int21h;退出OS

;定义一个取字符的子程序

;入口参数:

ds:

si中的字符

;出口参数:

字符的ASCII-->al

getcharproc

cld

main5:

lodsb

cmpal,0

jzmain4

callputchar

jmpmain5

main4:

ret

getcharendp

;定义一个显示字符的子程序

;入口参数:

al中的ASCII

;出口参数:

显示字符

putcharproc

movdl,al

movah,02h

int21h

ret

putcharendp

mainendp

codeends

endmain

运行结果:

第八题:

源程序:

;以10进制形式显示内存中一有符号字节数据

datasegmentpara

vardb0e6h

bufdb3dup(0)

str1db0dh,0ah,'Theconvertedresultis:

$'

dataends

ss_segsegmentstack

db100dup(0)

ss_segends

codesegmentpara

assumecs:

code,ss:

ss_seg,ds:

data

mainprocfar

movax,data;数据段赋值

movds,ax

leadx,str1

movah,9;显示输出结果提示

int21h

movcx,3;设定除法的循环次数

movbx,3

moval,var

andax,0ffh;ah清零

pushax;保存AX中的var数据

cmpal,0;判断数据的正负

jgemain1

movdl,'-'

movah,2

int21h

popax

negal;求负数的相反数

main1:

;循环除法求余数,既是个位,十位,百位

movdl,10

divdl

decbx

movbuf[bx],ah

andax,0ffh;ah清零

loopmain1

movcx,3;设定显示字符的循环次数

movbx,0

circle:

;循环显示转换后的结果

addbuf[bx],30h

movdl,buf[bx]

movah,2

int21h

incbx

loopcircle

exit:

movax,4c00h

int21h;退出OS

mainendp

codeends

endmain

运行结果:

第九题:

源程序:

;将一个16位的无符号数var,转换为非压缩格式BCD码,存放在内存中buf开始的单元中

;(按高位在前、低位在后的顺序存放)

datasegmentpara

vardw65535

bufdb5dup(0)

dataends

ss_segsegmentstack

db100dup(0)

ss_segends

codesegmentpara

assumecs:

code,ss:

ss_seg,ds:

data

mainprocfar

movax,data;数据段赋值

movds,ax

movdx,16;左移16次

movsi,wordptrvar

circle1:

;先按照压缩格式的BCD码存储

shlsi,1

movcx,3

leabx,buf

circle2:

moval,[bx]

adcal,al

daa

mov[bx],al

incbx

loopcircle2

decdx

jnzcircle1;16次左移

leabx,buf;将压缩格式的转换为非压缩格式的BCD码

moval,[bx+2]

andal,0fh

mov[bx+4],al

moval,[bx+1]

pushax

movcl,4

shral,cl

mov[bx+3],al

popax

andal,0fh

mov[bx+2],al

moval,[bx]

pushax

shral,cl

mov[bx+1],al

popax

andal,0fh

mov[bx],al

movcx,5

circle3:

;转换为高位在前,低位在后的形式

moval,[bx]

movah,0

pushax

incbx

loopcircle3

leabx,buf

circle4:

popax

mov[bx],al

incbx

loopcircle4

movax,4c00h

int21h;退出OS

mainendp

codeends

endmain

运行结果:

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 人文社科 > 法律资料

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1