[Asm] Nhap n Va Xuat Ra n So Chan Dau Tien

F:\My ASM CODE\[ASM] NHAP N VA XUAT RA N SO CHAN DAU TIEN.

asm

Monday, April 11, 2011 11:53 PM

# NHAP SO N VA IN RA N SO CHAN DAU TIEN # BT2 _ PROJECT HOP NGU TUAN 6 # AUTHOR: huahongquan2007 # # FOR SOURCE CODE & MORE INFORMATION VISIT : itspiritclub.net # ############################################################################################### .data prompt1: .asciiz " HAY NHAP N \n" prompt2: .asciiz " KET QUA LA \n" space: .asciiz " " .text main: la $a0,prompt1 # Load address prompt addi $v0,$0,4 # PRINT STRING 1 syscall addi $v0,$0,5 # NHAP N syscall add $s0,$v0,$0 # LUU N vao $s0 la $a0,prompt2 # Load address prompt addi $v0,$0,4 # PRINT STRING 2 syscall addi $a0,$0,-1 # GAN GIA TRI $a0 = -1 addi $a1,$0,2 # LUU GIA TRI 2 VAO $a1 LOOP: beqz $s0,EXIT_LOOP # NEU N = 0 thi thoat khoi LOOP addi $a0,$a0,1 # TANG GIA TRI CUA $a0 len 1 jal kiemtra # KIEM TRA SO CHAN beqz $v0,khong_chan # NEU LA CHAN THI THUC HIEN addi $s0,$s0, -1 # GIAM GIA TRI N DI 1 addi $v0,$0,1 # PRINT INTEGER syscall addi $t2,$a0,0 # TAM THOI LUU $a0 vao $t2 la $a0,space # Load address space addi $v0,$0,4 # PRINT KHOANG CACH syscall addi $a0,$t2,0 # PHUC HOI LAI $a0 khong_chan: j LOOP

-1-

F:\My ASM CODE\[ASM] NHAP N VA XUAT RA N SO CHAN DAU TIEN.asm

Monday, April 11, 2011 11:53 PM

EXIT_LOOP: addi $v0,$0,10 #Exit syscall kiemtra: div $a0,$a1 # LAY $a0 chia cho $a1 ( 2 ) NEU MA CHAN THI HI SE LUU GIA TRI 0 mfhi $t1 # LOAD GIA TRI CUA HI VAO $t1 bnez $t1,ko_dung # NEU MA T1 KHAC 0 THI KHONG PHAI LA CHAN addi $v0,$0,1 # LUU GIA TRI V0 = 1 jr $ra ko_dung: addi $v0,$0,0 # LUU GIA TRI V0 = 0 jr $ra

-2-

Sign up to vote on this title
UsefulNot useful