首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 嵌入开发 > 汇编语言 >

[高分](朋友)学过汇编的都会

2012-03-13 
[高分](朋友求助)学过汇编的都会从键盘输入两个十进制数,按bcd原则相加,显示结果------------------------

[高分](朋友求助)学过汇编的都会
从键盘输入两个十进制数,按bcd原则相加,显示结果
----------------------------------------------
要具体程序,谢谢!!
在线等^..............

[解决办法]
; 从键盘输入一个数,参数AL指定格式
.286
publicinnum
codesegment
assumecs:code, ds:code
maxdigitdb0
db0
dw0
bwliddb0
plusdb0
valuedd0
plus_maxdb0; b0=1 got plus, b1=1 got maxdigit
abdhiddb0

innumprocfar
; IN:
; AL(b1_b0)=0 INPUT BYTE
; AL(b1_b0)=1 INPUT WORD
; AL(b1_b0)=2 INPUT LONG

; AL(b3_b2)=0 PERMIT BIN
; AL(b3_b2)=1 PERMIT DEC
; AL(b3_b2)=2 PERMIT HEX
; AL(b3_b2)=3 PERMIT ALL

; OUT:
; LONG IN DX:AX, WORD IN AX, BYTE IN AX(AH=0)

pushds
pushbx
pushcx
pushdx
pushsi

movbx, cs
movds, bx
movbl, al
andal, 03h
movbwlid, al
shrbl, 2
andbl, 3
movabdhid, bl

first:
cmpabdhid, 0
jzbin01
cmpabdhid, 1
jzdec01
cmpabdhid, 2
jzhex01
jmpall01
bin01:
movmaxdigit, 2
jmptot01
dec01:
movmaxdigit, 10
jmptot01
hex01:
movmaxdigit, 16
tot01:
movplus_max, 2
jmpinitval
all01:
movmaxdigit, 10
movplus_max, 0
initval:
movplus, 0
db66h
xorcx, cx
db66h
movword ptr value, cx; init value

inchrep:
callinchar
testplus_max, 1
jnznext1
cmpal, '- '
jnznext0
movplus, 0ffh
back0:
orplus_max, 1
calloutchar
jmpinchrep
next0:
cmpal, '+ '
jnznext1
jmpback0
next1:
testplus_max, 2
jnznext3
cmpal, 'B '
jzbini
cmpal, 'b '
jzbini
cmpal, 'H '
jzhexi
cmpal, 'h '
jzhexi
cmpal, 'D '
jzdeci
cmpal, 'd '
jzdeci
jmpnext3

bini:movmaxdigit, 2
jmpnext2

hexi:movmaxdigit, 16
jmpnext2
deci:
next2:
andsi, 0dfh
calloutchar
orplus_max, 3
next3:
subal, 30h
jsinchrep
cmpal, 0ah
jbnext4
andal, 0dfh
subal, 7
cmpal, 0ah
jbinchrep
next4:
cmpal, maxdigit
jaeinchrep
movcl, al

db66h
movax, word ptr value
db66h
mulword ptr maxdigit
db66h
addax, cx
adcdl, 0

cmpbwlid, 0
jzjudgeb
cmpbwlid, 1
jzjudgew
judgel:
cmpdl, 0
jmpnext5
judgew:
.386c
cmpeax, 0000ffffh
.286
jmpnext5

judgeb:
cmpah, 0
next5:
jainchrep

db66h
movword ptr value, ax
calloutchar
orplus_max, 3
jmpinchrep
innumend:
popsi
popdx
popcx
popbx

cmpplus, 0
jznotneg
db66h
negword ptr value
notneg:
movax, word ptr value
cmpbwlid, 2
jbnotlong
movdx, word ptr value+2
notlong:
popds
retf
innumendp

incharprocnear
movah, 0
int16h
movsi, ax
cmpal, 27
jzescch
cmpal, 0dh
jzentch
retn

escch:popax
movsi, '4\ '
calloutchar
callfeedline
jmpfirst

entch:popax


callfeedline
jmpinnumend
incharendp

feedlineprocnear
movsi, 000dh
calloutchar
movsi, 000ah
calloutchar
retn
feedlineendp

outcharprocnear
movax, si
movah, 0eh
int10h
retn
outcharendp

codeends
endinnum
[解决办法]
;显示一个数(DX:AX),如果是WORD就在AX,参数BX指定格式
.286
publicoutnum
codesegment
assumecs:code, ds:code

count1db0
count2db0
endchardb0
maxdigitdb0
db0
dw0
valuedw0
dw0
outnumprocfar
; IN:
; LONG IN DX:AX, WORD IN AX
; BL(b1_b0)=1 WORD
; 2 LONG
; BL(b3_b2)=0 BIN
; 1 DEC
; 2 HEX
; BL(b4)=1 HAS SIGN
; 0 HAS NOT SIGN
; BL(b5)=1 HAS BDHID
; 0 HAS NOT BDHID
; BH=DIGIT AMOUNT LIMIT

pushax
pushbx
pushcx
pushdx
pushds
movcx, cs
movds, cx
db66h
xorcx, cx
db66h
movvalue, cx
db66h
movword ptr maxdigit, cx
movvalue, ax
movcount1, bh
movcount2, bh

testbl, 10h
jznosign

testbl, 1
jnzwordsign
longsign:
testdh, 80h
jzplusid
lminusid:notax
notdx
incax
adcdx, 0
jmptotmin
wordsign:
testah, 80h
jzplusid
wminusid:
negax
totmin:
movcl, '- '
jmptotsid
plusid:
movcl, '+ '
totsid:
calloutchar

nosign:
movvalue+2, dx
testbl, 2
jnzoutlong
movvalue+2, 0
outlong:
db66h
movax, value
db66h
xordx, dx
testbl, 0ch
jzbini
testbl, 04h
jnzdeci
hexi:
movmaxdigit, 16
movendchar, 'H '
jmptotdig
deci:
movmaxdigit, 10
movendchar, 'D '
jmptotdig
bini:
movmaxdigit, 2
movendchar, 'B '
totdig:
xordx, dx
db66h
divword ptr maxdigit
pushdx
deccount1
jnztotdig
divend:
popcx
orcl, 30h
cmpcl, '9 '
jbedigit10
addcl, 7
digit10:
calloutchar
deccount2
jnzdivend

testbl, 20h
jznobdh
movcl, endchar
calloutchar
nobdh:
popds
popdx
popcx
popbx
popax
retf
outnumendp

outcharprocnear
xchgax, cx
movah, 0eh
int10h
xchgax, cx
retn
outcharendp

codeends
endoutnum

热点排行