我只是試圖編寫一個簡單的程序,它需要用戶輸入x個整數,然後讓用戶輸入它們,然後使用子例程來計算數組並打印出總和。MASM將數組中元素的總和加起來
我想將EAX中的數組地址和數組元素的數量傳遞給EBX。
;Lab 4
title Template Lab4 Adder
INCLUDE Irvine32.inc ;32bit assembler
.data
theansweris DWORD ?
welcometoadder BYTE "Welcome to adder",0dh,0ah,0
howmanynumbers BYTE "How many numbers would you like to add?:",0dh,0ah,0
enteranumber BYTE "Enter a Number:",0dh,0ah,0
youentered BYTE "You entered:",0dh,0ah,0
thesumis BYTE "The sum of the numbers is:",0dh,0ah,0
space BYTE " ",0dh,0ah,0
readStr DB 50 DUP(?) ;allocates 50 BYTES WITH ?
var1 DWORD ?
testz DWORD 0
sum BYTE 11 DUP(?), " is the sum.", 0dh, 0ah
numArray DWORD ?
numElts DWORD 100
num DWORD ?
resultLbl BYTE "Results", 0
.code
main PROC
call Clrscr
mov edx, OFFSET welcometoadder
call WriteString
;mov ecx, 100 ; loop count (size of array)
;lea ebx, numElts ; get address of the array
mov edx, OFFSET howmanynumbers
call WriteString
mov edx,OFFSET enteranumber
call WriteString
call ReadInt
mov edx,OFFSET youentered
call WriteString
mov ebx,eax
mov edx,ebx
call WriteInt
mov edx, OFFSET space
call WriteString
;mov ebx,edx
mov ecx,ebx
lea ebx,NumElts
LOOP1:
mov edx, OFFSET enteranumber
call WriteString
mov edx, OFFSET space
call WriteString
call ReadInt
mov [ebx], eax ; store in the array
add ebx, 4 ; get address of next array elt
cmp ecx,0
je LOOP2
loop LOOP1 ; repeat nbrElts times
LOOP2:
call DumpRegs
;mov eax,[ebx] ;get the num
;add edx,eax ;increase the sum
;add ebx,4 ;next array element
;loop LOOP2
; CALL ADDER
;ADDER PROC
; add bx, cx
; add bx, cx
; add ax, bx
;mov edx, OFFSET thesumis
;call WriteString
; RET
;ADDER ENDP
exit
main ENDP
END main
我編輯了你的答案,刪除了一些不相關的元評論。關於評論的50個聲望要求,您可以[在meta上閱讀更多內容](https://meta.stackoverflow.com/questions/252133/50-reputation-points-to-make-comments) – ryanyuyu