Assembly: Tambah Nombor Genap & Dapatkan purata
Kadang-kadang aku pun konpius tapi soalan mcm ni biasa keluar: Write an assembly language program segment to add two even number N1 and N2. The average is computed and stored in a varible named AVG(Assume AVG has been declared as an 8 bit length) jawapan(aku rasa x berapa bagus): .MODEL SMALL .STACK 64 .DATA TWO db ? i dw ? count dw ? Sum dw ? AVG db ? N1 dw ? N2 dw ? .CODE main proc far MOV Sum,0 MOV TWO,2 MOV count, 0 MOV i,0 start: INC i Mov AX,i Mov N2, AX ;AX to N2 DIV TWO CMP AH, 1 ;Kalau nombor ganjil bahagi dua mesti dapat baki 1 JE start ADD BX, i ;N1 + N2 Mov N1, BX INC count ;Kira berapa kali nombor genap ditambah CMP i, 10 JGE stop JMP start stop: MOV Sum, BX Mov AX, Sum DIV count ; Bahagi jumlah dengan bilangan tambah MOV AVG, AL ; Masuk nilai purata ke dalam AVG INT 21h main endp end main Mari kita fahamkan sesama: Bila bahagi degan operasi DIV, AX akan ada dua nilai berbeza dekat...