日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

计算两个数之间所有整数的和_汇编语言:输入2个0–99之间的整数,对其做乘法运算,在屏幕上显示出该乘积对应的二进制和十六进制数...

發布時間:2025/3/20 编程问答 31 豆豆

實驗要求:

(1)在屏幕提示:“please input the first number(0–99): ”后,輸入一個0–99之間的整數。

若所輸入的數不在此范圍內,或輸入其它字符,則屏幕提示:“input an invalid number, input again!”;

(2)在屏幕提示:“please input the second number(0–99): ”后,輸入一個0–99之間的整數。

若所輸入的數不在此范圍內,或輸入其它字符,則屏幕提示:“input an invalid number, input again!”。

(3)對2個整數做乘法運算。

(4)在屏幕上顯示出乘積所對應的二進制和十六進制數;

顯示部分功能要求用子程序實現。

完整代碼如下:

DATAS SEGMENT

;此處輸入數據段代碼

string1 db "please input the first number(0-99):",0dh,0ah,"$"

string2 db "please input the second number(0-99):",0dh,0ah,"$"

string3 db "input an invalid number, input again!",0dh,0ah,"$"

linefeed db 0dh,0ah,'$'

buff1 db 5

num1 db ?

chars1 db 5 dup(0)

buff2 db 5

num2 db ?

chars2 db 5 dup(0)

temp db 10

finum db 0

senum db 0

DATAS ENDS

STACKS SEGMENT

;此處輸入堆棧段代碼

STACKS ENDS

CODES SEGMENT

ASSUME CS:CODES,DS:DATAS,SS:STACKS

START:

MOV AX,DATAS

MOV DS,AX

;此處輸入代碼段代碼

mov ah,09h

mov dx,offset string1

int 21h

input1:

mov dx,offset buff1

mov ah,0ah

int 21h

mov dx,offset linefeed

mov ah,09h

int 21h

check1:

lea bx,chars1

mov cl,num1

mov ch,0

nextt1:

mov dx,[bx]

cmp dl,'0'

jb again1;小于就

cmp dl,'9'

ja again1;大于就

inc bx

loop nextt1

jmp inputcontinue

again1:

mov dx,offset string3

mov ah,09h

int 21h

jmp input1

inputcontinue:

mov ah,09h

mov dx,offset string2

int 21h

input2:

mov dx,offset buff2

mov ah,0ah

int 21h

mov dx,offset linefeed

mov ah,09h

int 21h

check2:

lea bx,chars2

mov cl,num2

mov ch,0h

nextt2:

mov dx,[bx]

cmp dl,'0'

jb again2;小于就

cmp dl,'9'

ja again2;大于就

inc bx

loop nextt2

jmp putcontinue

again2:

mov dx,offset string3

mov ah,09h

int 21h

jmp input2

putcontinue:

firstnum:

lea bx,chars1

mov al,[bx]

;and al,0fh;ascii碼變成數值

sub al,30h

push ax

mov cl,num1 ;是否是單位數操作

cmp cl,1

jne doubchange1 ; num1!=1 ?-

jmp secondnum

doubchange1: ;將字符串變為十六進制數字保存在al內!

mul temp

mov ah,al

mov al,[bx+1]

;and al,0fh

sub al,30h

add al,ah

push ax;保存!

secondnum:

lea bx,chars2

mov al,[bx]

;and al,0fh

sub al,30h

mov cl,num2

cmp cl,1

jne doubchange2

jmp multi

doubchange2:

mul temp

mov ah,al ;暫時存放在ax高八位

mov al,[bx+1]

; and al,0fh

sub al,30h

add al,ah

multi:;做乘法運算

mov bl,al

pop ax

mul bl

output1: ;輸出結果十六進制

push ax

mov al,ah

call DisplayforAl_H

pop ax

call DisplayforAl_H

push ax ;暫時保存結果

mov dx,'H'

mov ah,02h

int 21h

mov dx,offset linefeed; 換行!

mov ah,9

int 21h

output2: ;輸出結果二進制

pop ax

mov bx,ax

call DisplayforBx_B

mov dx,'B'

mov ah,02h

int 21h

MOV AH,4CH

INT 21H

DisplayforAl_H proc near ;輸出al十六進制數據也就是兩個字符

push ax ;過程中使用了AX、CX和DX,所以先保存

push cx

push dx

push ax ;暫存ax

mov dl,al ;轉換al的高4位

mov cl,4

shr dl,cl ;把高四位移到后4位

;or dl,30h ;al高4位變成0011,相當于在dl上加30h

add dl,30h

cmp dl,39h

jbe DisplayforAl1;小于等于

add dl,7 ;是0Ah~0Fh,還要加上7 A:65,9:57,10:58+7=65:A

DisplayforAl1:

mov ah,2 ;顯示

int 21h

pop dx ;將原ax的值恢復到dx

and dl,0fh ;去掉高4位保留低4位

;or dl,30h

add dl,30h

cmp dl,39h

jbe DisplayforAl2

add dl,7

DisplayforAl2:

mov ah,2 ;顯示

int 21h

pop dx

pop cx

pop ax

ret ;過程返回

DisplayforAl_H endp

DisplayforBx_B proc near ;顯示二進制

mov cx,16 ;顯示總共位數

L:

rol bx,1;左移,從頭至尾依次移至CF中

mov dl,0

adc dl,30h;dl=dl+30h+CF

mov ah,02h

int 21h

loop L

ret

DisplayforBx_B endp

MOV AH,4CH

INT 21H

CODES ENDS

END START

運行結果如下圖:

總結

以上是生活随笔為你收集整理的计算两个数之间所有整数的和_汇编语言:输入2个0–99之间的整数,对其做乘法运算,在屏幕上显示出该乘积对应的二进制和十六进制数...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。