0
我試圖找到這個數組的AVG:1742,1065,-67,-2988,-796,-1000,31,-67,-100,1180 我相信我的方法來改變POS的數量到NEG是worng。 我的編程需要計算上述數組,然後在AVG爲NEG或POS的情況下打印massege,並且始終打印該AVG是POS,即使它不是。 這裏是到目前爲止我的代碼:在計算平均值時,我應該將輸入的符號標準化嗎?
; lab56.asm ; .MODEL SMALL .STACK 100h .DATA AVG_NEG DB 'THE AVG IS NEG',13,10,'$' AVG_POS DB 'THE AVG IS POS',13,10,'$' INDEX DB 'Numbers that are larger than the average are in indexes:',13,10,'$' RES DB ' ','$' ARR DW 1742,1065,-67,-2988,-796,-1000,31,-67,-100,1180 Ten DW 10 AVG DW 0 temprint DB ' ','$' ;Program start here: .CODE MOV AX,@DATA ; DS can be written to only through a register MOV DS,AX ; Set DS to point to data segment LEA SI, ARR ; ; SUMUP MOV CX,10 ;10 variables in array Sum: MOV AX,[SI] CMP AX,0 JG Pos_label XOR AX,0000000000000000b ADD AX,0000000000000001b Pos_label: ADD AVG,AX ADD SI,2 ;move to the next number LOOP Sum ; Divided by 10 to get the AVG CWD ; AX -> DX:AX IDIV Ten MOV AVG,AX ; print ; Check if NEG or POS CMP AVG,0 JG Avg_label MOV AH,9 ; Set print option for int 21h MOV DX,OFFSET AVG_NEG ; Set DS:DX to point to AVG_NEG INT 21h JMP continue Avg_label: MOV AH,9 ; Set print option for int 21h MOV DX,OFFSET AVG_POS ; Set DS:DX to point to AVG_POS INT 21h continue: ; ;Program end's here: MOV AH,4Ch ; Set terminate option for int 21h INT 21h ; Return to DOS (terminate program) END
我將第一部分改爲: ; SUMUP \t MOV CX,10 \t \t; 10個變量在陣列 \t MOV AX,0 薩姆: \t MOV AX,[SI] \t ADD SI,2 \t \t;移動到下一個數 \t ADD AVG, AX LOOP Sum 然後我打印我的總和,我得到64541它就像它不能讀取負數 –
你需要做一些調試。如你所知,你正在尋找的總和是-1000。這與64541有什麼關係?請記住考慮有符號和無符號整數的意義;如果你不知道這是什麼意思,請問你的導師。 –