資料的求和 求均

2021-09-03 08:09:49 字數 1938 閱讀 3577

注:原部落格賬號密碼丟失,故將本科期間的筆記搬運至此

在首位址為buf的記憶體中,連續存放者20個單位元組無符號數,將它們相加,得到16位的結果,並將它存到首址為res的單元。請自行設計資料,比如設計它們為0~9及90~99,那麼求和後的結果應為990(03deh),繼續求這批資料的平均值,最後將運算結果——和、商、餘數分別存放到res1(字)和res2(位元組)res3(位元組)等3處

datas segment

;此處輸入資料段**

buf db 0,1,2,3,4,5,6,7,8,9,90,91,92,93,94,95,96,97,98,99

res1 dw ?

res2 db ?

res3 db ?

datas ends

stacks segment

;此處輸入堆疊段**

stacks ends

codes segment

assume cs:codes,ds:datas,ss:stacks

start:

mov ax,datas

mov ds,ax

;此處輸入**段**

;巨集 顯示乙個字元

dispchar macro char

mov ah,2

mov dl,char

int 21h

endm

;巨集定義完成

;巨集 顯示字串

dispmsg macro message

mov ah,9

lea dx,message

int 21h

endm

;巨集定義完成

;巨集 顯示十六進製制數的四位

disphex macro hexdata

local disphex1

push ax

push bx

push cx

push dx

mov bx,hexdata

mov cx,0404h

disphex1: rol bx,cl

mov al,bl

and al,0fh

call htoasc

dispchar al

dec ch

jnz disphex1

pop dx

pop cx

pop bx

pop ax

endm

;巨集定義完成

mov cx,lengthof buf

mov bx,0h

lea si,buf

again:

mov al,byte ptr [si]

cbw

adc bx,ax

inc si

loop again

mov word ptr res1,bx

disphex bx

mov ax,bx

mov cl,lengthof buf

div cl

mov res2,al

mov res3,ah

disphex ax

mov ah,4ch

int 21h

;子程式十六進製制轉ascii

htoasc proc

push bx

mov bx,offset ascii

and al,0fh

xlat ascii

pop bx

retascii db 30h,31h,32h,33h,34h,35h,36h,37h,38h,39h

db 41h,42h,43h,44h,45h,46h

htoasc endp

codes ends

end start

---------------------

原文:

資料的求和 求均

datas segment 此處輸入資料段 buf db 0,1,2,3,4,5,6,7,8,9,90,91,92,93,94,95,96,97,98,99 res1 dw res2 db res3 db datas ends stacks segment 此處輸入堆疊段 stacks ends c...

求和求到手軟

描述 ln想要知道大家的小學數學好不好。現在他想讓你求出幾個數的和。你能搞定麼?輸入多組測試資料 一組測試資料一行。輸出乙個數sum,表示結果。保證在 int 範圍內 樣例輸入 2 3 5 5 6 7 8 1 2 3 4 5 6 7 8 9 10樣例輸出 10 2655 如下這道題考察的點很清晰,就...

oracle中累計求和 oracle累計求和

poj2001 shortest prefixes trie樹應用 沉迷wow又頹了兩天orz,暴雪爸爸要在國服出月卡了.這是要我好好學習嗎?趕緊來刷題了.oj 題目大意是求所有字串裡每乙個字元 硬體相關 jtag介面 jtag joint test action group,聯合測試行動小組 是一...