我们的任务是从用户那里获得5个输入
应从9中减去输入数字,然后我们应将所有总和求和
例如输入5,2,4,7,1 9-5 = 4,9-2 = 7,9-4 = 5,9-7 = 2,9-1 = 8 那么我们需要将结果相加,以便4 + 7 + 5 + 2 + 8 = 26
并显示
的结果我已经进行了计算,并将它们放置在一个循环中,但是总和仅显示上一次计算的值,而不是总和
.model small
.stack 100h
.data
num1 db
num2 db 9
result db ?
sum db
msg1 db 10, 13,"Enter a number: $", 10, 13
msg2 db 10, 13,"Difference is: $",10, 13
msg3 db 10, 13,"Sum is: $",10, 13
.code
main proc
mov ax, @data
mov ds, ax
mov cx,5
process:
mov dx, offset msg1
mov ah,9 ; used to print the string/msg with
int 21h ;this
mov ah, 1 ;READ a Character from Console,
;Echo it on screen and save the
;value entered in AL register
int 21h
sub al, 30h ;keep the value enter in bcd form
mov num1, al ;move num1 to al
;al is used for input
;sub al, 30h
mov al, num2 ;move num2 to al
sub al, num1 ;
mov result, al ;move whats in al to result
mov bl,al
add sum,bl
;add al,sum
mov ah,0 ;clears whats in ah
aaa ;used to convert the result to bcd
;and first digit is stored in ah
;second digit stored in al
add ah, 30h ;convert whats in ah to ascii by adding 30h
add al, 30h ;convert whats in al to ascii by adding 30h
mov bx, ax ;saving whats in ah and al in bx register
mov dx, offset msg2
mov ah,9 ; used to print the string/msg
int 21h
;the following is used to print whats in the bh register
;dl is used for output
;2 or 2h means to write/print whats in dl
;so the value to be printed is moved to dl
mov ah,2
mov dl, bh
int 21h
;the following is used to print whats in bl
mov ah,2
mov dl, bl
int 21h
loop process
mov dx, offset msg3
mov ah,9 ; used to print the string/msg
int 21h
mov ah,2
mov dl, bh
int 21h
;the following is used to print whats in bl
mov ah,2
mov dl, bl
int 21h
mov ah, 4ch ;4ch means to return to OS i.e. the end
;of program
int 21h
main endp ;ends the code
end main ;ends main
我希望我的总和为26。相反,我得到8
答案 0 :(得分:1)
{ "status_message": "Found route between points", "route_geometry": "m{`G_cyxRaAmALMtAyAj@g@RIZG|@KTC??RCxBQ\\KAOa@sDAQWwBM_AUmBEa@Ky@_@kDKoAIgAAs@Ce@?M|@_@PINUFk@Ik@e@aCu@wBeBoD_A}AmBqC{@iA_AeAyAqA{LmKmAu@k@g@y@Jk@r@k@r@GP@PFJhAt@oEnGw@i@QTMPs@g@}AzBr@d@JQ", "status": 0, "route_instructions": [ [ "Head", "SINARAN DRIVE", 56, "1.320394,103.844478", 18, "56m", "North East", "North", "driving", "Head Northeast On Sinaran Drive" ], [ ... ], ... ], "route_name": [ "MOULMEIN ROAD", "WHAMPOA ROAD" ], "route_summary": { "start_point": "SINARAN DRIVE", "end_point": "WHAMPOA ROAD", "total_time": 390, "total_distance": 2675 }, "viaRoute": "JALAN BAHAGIA", "subtitle": "Fastest route, assuming usual traffic", "phyroute": { "status_message": "Found route between points", "route_geometry": "m{`G_cyxRaAmALMtAyAj@g@RIZG|@KTC??Ao@BcB?kCBIHK|Ay@M_AUmBEa@Ky@_@kDKoAIgAAs@Ce@?M?OBw@BsCEq@Q{@Qm@KQGMaCNM@iFXO?sCNo@LCa@QaICe@EI?EBQTi@Ha@@c@CMGWOYOOgEgD{BeBuB}AoEnGw@i@QTMPs@g@}AzBr@d@JQ", "status": 0, "route_instructions": [ [ "Head", "SINARAN DRIVE", 56, "1.320394,103.844478", 18, "56m", "North East", "North", "driving", "Head Northeast On Sinaran Drive" ], [ ... ], ... ], "route_name": [ ... ], "route_summary": { ... }, "viaRoute": "BALESTIER ROAD", "subtitle": "Shortest distance" } }
这缺少一个操作数。写下sum db
但是总和仅显示上一次计算的值,而不是总和
在显示第三条消息和相应值之间,您忘记了重新计算sum db 0
的必需内容。您只是简单地重用了其中已有的内容!
BX