汇编编程问题:用汇编语言编写程序,从屏幕输入10个两位的十制数(包含正数和负数)
- 资格考试
- 2023-04-01 17:43:58
用汇编语言编写程序段,实现从键盘输入十个一位10进制数后累加以非压缩BCD码形式存放在AH和AL中.
codesegment
assumecs:code
org100h
start:
jmpbbb
lfcrdb13,10,'$'
bbb:
pushcs
popds
callinputnum
movah,9
leadx,lfcr
int21h
leasi,array
movch,0
movcl,byteptr[num]
movax,0
lp:
addax,wordptr[si]
daa;十进制加法调整指令
incsi
incsi
looplp
calldispnum
movah,4ch
int21h
dispnumprocnear
;将要显示的数据放入AL中
movdl,al;将AL暂存在DL中
andal,0Fh;取AL的低4位
movbl,al;非压缩的bcd码
addbl,30h;转成ASCii码
moval,dl;取回AL并经以下4次右移取出AL的高4位
shral,1
shral,1
shral,1
shral,1
movbh,al;非压缩的bcd码
addbh,30h;转成ASCii码
movax,bx;非压缩的两位数的ASCii码存放在AX中
movbyteptr[y+4],al
movbyteptr[y+3],ah
movah,9
leadx,y
int21h
ret
ydb10,13,0,0,0,'$'
dispnumendp
inputnumprocnear
;输入的数据以一个空格分隔,以回车符结束输入
leadi,array;将数组第一个元素的有效地址置入DI
movbyteptr[num],0
stin:
movax,0
pushax
again1:
movah,1
int21h
movbyteptr[char],al
cmpal,13
jeline0
cmpal,''
jeline0
subal,30h
movah,0
movsi,ax
popax
movcl,10
movch,0
mulcx
addax,si
pushax
jmpagain1
line0:
popax
movwordptr[di],ax
incbyteptr[num]
cmpbyteptr[char],13
jestinend
incdi
incdi
jmpstin
stinend:
ret
arraydw100dup(0)
numdb0
chardb?
inputnumendp
codeends
endstart
微机原理,用汇编语言编写,给定一组数据,大概十个数,统计正数,负数,0的个数,并显示到屏幕上(重要
"1.编制一段程序求出下列公式中z的值并放在result单元,注x,y,result分别定义成字类型变量 \ z=((x+y)*4-y)/2 \ \ 答: \ mov ax,x \ add ax,y \ shl ax,1 \ shl ax,1 \ sub ax,y \ shr ax,1 \ mov result,ax\ \ 2.试编写一小侧面硬指令序列,在屏幕上显示出\"hello everybody!\"字符串,该字符串已在数据段定义好为变量string \ 答: \ lea dx,string \ mov ah,9 \ int 21h"【摘要】 微机原理,用汇编语言编写,给定一组数据,大概用汇编语言编写从键盘输入两个两位的十进制数,做加法运算,并显示结果。
codesegment
assumecs:code
org100h
start:
jmpbbb
lfcrdb13,10,'$'
bbb:
pushcs
popds
callinputnum
movah,9
leadx,lfcr
int21h
leasi,array
movch,0
movcl,byteptr[num]
movax,0
lp:
addax,wordptr[si]
incsi
incsi
looplp
;movcl,byteptr[num]
;divcl
calldispnum
movah,1
int21h
movah,4ch
int21h
dispnumprocnear
;将要显示的数据放入AL中
movah,0
movcl,10
divcl
movbyteptr[y+4],ah;保存个位
movah,0
divcl
movbyteptr[y+3],ah;保存十位
movah,0
movbyteptr[y+2],al;保存百位
moval,byteptr[y+2]
addal,30h;百位转ASC2
movbyteptr[y+2],al
moval,byteptr[y+3]
addal,30h;十位转ASC2
movbyteptr[y+3],al
moval,byteptr[y+4]
addal,30h;个位转ASC2
movbyteptr[y+4],al
movah,9
leadx,y
int21h
ret
ydb10,13,0,0,0,'$'
dispnumendp
inputnumprocnear
;输入的数据以一个空格分隔,以回车符结束输入
leadi,array;将数组第一个元素的有效地址置入DI
movbyteptr[num],0
stin:
movax,0
pushax
again1:
movah,1
int21h
movbyteptr[char],al
cmpal,13
jeline0
cmpal,''
jeline0
subal,30h
movah,0
movsi,ax
popax
movcl,10
movch,0
mulcx
addax,si
pushax
jmpagain1
line0:
popax
movwordptr[di],ax
incbyteptr[num]
cmpbyteptr[char],13
jestinend
incdi
incdi
jmpstin
stinend:
ret
arraydw100dup(0)
numdb0
chardb?
inputnumendp
codeends
endstart
用汇编语言编写代码转换程序。编程实现十制数和二进制数之间的转换(要求键入被转换数,转换的结果要求从
dsegsegment
msg0db'pleaseInputadecimalnumber<65536:$'
dsegends
assumecs:cseg,ds:dseg
csegsegment
start:
movax,dseg
movds,ax
movah,9
leadx,msg0
int21h
callreadn
movah,0eh
moval,0dh
int10h
moval,0ah
int10h
callprintBin
movah,4ch
int21h
;readinputdecimalnumber
;storeinbx
readnprocnear
movbx,0
movcx,10
movsi,0
r0:
movah,7
int21h
cmpal,0dh
jzr3
cmpal,'0'
jbr0
cmpal,'9'
jar0
movah,0eh
int10h
andal,0fh
movah,0
xchgax,bx
mulcx
addbx,ax
cmpbx,65535
jbr0
r3:
ret
readnendp
;print(bx)->binary
printBinprocnear
movcx,16
movah,0eh
p1:
rolbx,1
moval,bl
andal,1
xoral,30h
int10h
loopp1
ret
printBinendp
csegends
endstart
汇编语言程序(输入十个负数,输出其中最小的)
ORG 0000H LJMP MAIN0 ORG 0030H MAIN0:MOV A,#10H ACALL MAIN ;长调用排序程序 MOV P1,A SJMP $ MAIN: ;子程序入口 MOV R6,#00 ;起停标志位 LOOP:CLR 00H ;置换标志位 MOV R0,#40H ;数据存储单元 MOV R7,#10 ;循环次数控制 JIXU:MOV A,@R0 ;取第一个数 MOV 2AH,A ;存储 INC R0 ;调整数据指针 MOV 2BH,@R0 ;取第二个数,存储 CLR C ;清零 SUBB A,@R0 ;减法 JNC NEXT ;判断大小 MOV A,@R0 ;交换展开全文阅读