當前位置:編程學習大全網 - 編程語言 - 求壹簡單的匯編程序(最好是加法程序:如...加到...),要求有輸入和輸出並且希望每步都有註釋 急

求壹簡單的匯編程序(最好是加法程序:如...加到...),要求有輸入和輸出並且希望每步都有註釋 急

樓上的~貌似他要的是匯編的程序~

DATAS SEGMENT

ts1 db 'please input first number:$'

ts2 db 'please input second number:$'

error db 'error!please input again!',0ah,0dh,'$'

ts3 db 'sum=$'

again db 'again?(y/n)$'

DATAS ENDS

CODES SEGMENT

ASSUME CS:CODES,DS:DATAS

input proc

push bx

push cx

push dx

a0003:

xor bx,bx ;BX保存結果

a0001:

mov ah,1 ;輸入壹個字符

int 21h

cmp al,0dh

je a0004

cmp al,'0' ;不是0到9之間的字符,則輸入數據結束

jb a0002

cmp al,'9'

ja a0002

sub al,30h ;是0到9之間的字符,則轉換為二進制數

shl bx,1 ;利用移位指令,實現數值乘10: BX=BX*10

mov dx,bx

shl bx,1

shl bx,1

add bx,dx

mov ah,0

add bx,ax ;已輸入數值乘以10後,與新輸入的數值相加

jmp a0001 ;繼續輸入字符

a0002:

lea dx,error

mov ah,09h

int 21h

jmp a0003

a0004:

mov ax,bx ;設置出口參數

pop dx

pop cx

pop bx

ret ;子程序返回

input endp

enter1 proc

push ax

push dx

mov ah,02h

mov dl,0dh

int 21h

mov dl,0ah

int 21h

pop dx

pop ax

ret

enter1 endp

START:

MOV AX,DATAS

MOV DS,AX

a0006:

lea dx,ts1

mov ah,09h

int 21h

call input

call enter1

mov bx,ax

lea dx,ts2

mov ah,09h

int 21h

call input

call enter1

push ax

lea dx,ts3

mov ah,09h

int 21h

pop ax

add ax,bx

mov bl,100

div bl

mov dl,al

xchg ah,al

mov ah,0

mov cx,ax

add dl,30h

mov ah,02h

int 21h

mov bl,10

mov ax,cx

div bl

mov dl,al

xchg ah,al

mov ah,0

mov cx,ax

add dl,30h

mov ah,02h

int 21h

mov ax,cx

mov dl,al

add dl,30h

mov ah,02h

int 21h

call enter1

lea dx,again

mov ah,09h

int 21h

mov ah,01h

int 21h

cmp al,'y'

je a0006

cmp al,'Y'

je a0006

MOV AH,4CH

INT 21H

CODES ENDS

END START

我測試過了~基本沒什麽問題~999壹下的加法不會出錯了~超過999就有點問題了~

  • 上一篇:VBA是什麽啊?
  • 下一篇:睡前晚安童話故事五篇
  • copyright 2024編程學習大全網