1. Trang chủ
  2. » Công Nghệ Thông Tin

Bài tập hợp ngữ MIPS 1

9 40 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Nội dung

Xây dựng chương trình hợp ngữ MIPS sau: 1. Viết chương trình nhập vào năm sinh và năm hiện tại, in ra số tuổi. Ví dụ: Nam hien tai: 2010 Nam sinh cua ban: 1989 Ket qua: ban duoc 21 tuoi. 2. Viết chương trình, thực hiện nhập vào một ký tự và in mã ASCII tương ứng của ký tự đó. Ví dụ: Nhap ky tu: B Ma ASCII tuong ung: 42 3. Nhập vào 3 số a, b, c, in ra màn hình 3 số này theo thứ tự tăng dần. Ví dụ: So a: 3 So b:...

Bài tập hợp ngữ MIPS Xây dựng chương trình hợp ngữ MIPS sau: Viết chương trình nhập vào năm sinh năm tại, in số tuổi Ví dụ: Nam hien tai: 2010 Nam sinh cua ban: 1989 Ket qua: ban duoc 21 tuoi Viết chương trình, thực nhập vào ký tự in mã ASCII tương ứng ký tự Ví dụ: Nhap ky tu: B Ma ASCII tuong ung: 42 Nhập vào số a, b, c, in hình số theo thứ tự tăng dần Ví dụ: So a: So b: So c: Sau sap thu tu: Nhập vào số a, b, c, d (không dùng mảng liệu): a In số lớn nhỏ b In số lớn nhỏ Ví dụ: So a: So b: So c: So d: So lon nhat: va So nho nhat: Hai so khong phai la so lon nhat va nho nhat: Bài 1: .data s1: asciiz s2: asciiz s3: asciiz s4: asciiz text "Nam hien tai: " "Nam sinh cua ban: " "Ket qua: ban duoc " " tuoi" main: la $a0, s1 li $v0, syscall li $v0, syscall move $t0, $v0 la $a0, s2 li $v0, syscall li $v0, syscall move $t1, $v0 sub $t2, $t0, $t1 addi $t2, $t2, li $v0, la $a0, s3 syscall move $a0, $t2 li $v0,1 syscall li $v0, la $a0, s4 syscall Bài 2: data s1: asciiz "Nhap ky tu: " s2: asciiz "\nMa ASCII tuong ung: " text main: la $a0, s1 li $v0, syscall li $v0, 12 syscall move $t0, $v0 la $a0, s2 li $v0, syscall move $a0, $t0 li $v0, syscall Bài 3: data s1: asciiz s2: asciiz s3: asciiz s4: asciiz "So a: " "So b: " "So c: " "Sau sap thu tu: " .text main: la $a0, s1 li $v0, syscall li $v0, syscall move $t0,$v0 la $a0, s2 li $v0, syscall li $v0, syscall move $t1,$v0 la $a0, s3 li $v0, syscall li $v0, syscall move $t2,$v0 slt $s0,$t1,$t0 bne $s0,$0,L1 j Next1 L1: move $t3,$t0 move $t0,$t1 move $t1,$t3 Next1: slt $s0,$t2,$t0 bne $s0,$0,L2 j Next2 L2: move $t3,$t0 move $t0,$t2 move $t2,$t3 Next2: slt $s0,$t2,$t1 bne $s0,$0,L3 j Next3 L3: move $t3,$t2 move $t2,$t1 move $t1,$t3 Next3: la $a0, s4 li $v0, syscall move $a0, $t0 li $v0, syscall li $a0, 32 li $v0, 11 syscall move $a0, $t1 li $v0, syscall li $a0, 32 li $v0, 11 syscall move $a0, $t2 li $v0, syscall Bài 4: data _a: asciiz "So a: " _b: asciiz "So b: " _c: asciiz "So c: " _d: asciiz "So d: " _max: asciiz "So lon nhat: " _min: asciiz " va So nho nhat: " _other: asciiz "\nHai so khong phai la lon nhat va nho nhat: " text main: la $a0,_a li $v0,4 syscall li $v0,5 syscall move $t0,$v0 la $a0,_b li $v0,4 syscall li $v0,5 syscall move $t1,$v0 la $a0,_c li $v0,4 syscall li $v0,5 syscall move $t2,$v0 la $a0,_d li $v0,4 syscall li $v0,5 syscall move $t3,$v0 slt $s0,$t1,$t0 beq $s0,$0, L1 j L2 L1: move $t4,$t0 move $t0,$t1 move $t1,$t4 L2: slt $s0,$t2,$t0 beq $s0,$0, L3 j L4 L3: move $t4,$t0 move $t0,$t2 move $t2,$t4 L4: slt $s0,$t3,$t0 beq $s0,$0, L5 j L6 L5: move $t4,$t0 move $t0,$t3 move $t3,$t4 L6: slt $s0,$t2,$t1 beq $s0,$0, L7 j L8 L7: move $t4,$t1 move $t1,$t2 move $t2,$t4 L8: slt $s0,$t3,$t1 beq $s0,$0, L9 j L10 L9: move $t4,$t1 move $t1,$t3 move $t3,$t4 L10: slt $s0,$t3,$t2 beq $s0,$0, L11 j L12 L11: move $t4,$t2 move $t2,$t3 move $t3,$t4 L12: la $a0, _max li $v0, syscall move $a0, $t0 li $v0, syscall la $a0, _min li $v0, syscall move $a0, $t3 li $v0, syscall la $a0, _other li $v0, syscall move $a0, $t2 li $v0,1 syscall li $a0, 32 li $v0,11 syscall move $a0, $t1 li $v0,1 syscall ... L8 L7: move $t4,$t1 move $t1,$t2 move $t2,$t4 L8: slt $s0,$t3,$t1 beq $s0,$0, L9 j L10 L9: move $t4,$t1 move $t1,$t3 move $t3,$t4 L10: slt $s0,$t3,$t2 beq $s0,$0, L 11 j L12 L 11: move $t4,$t2 move... $t3,$t2 move $t2,$t1 move $t1,$t3 Next3: la $a0, s4 li $v0, syscall move $a0, $t0 li $v0, syscall li $a0, 32 li $v0, 11 syscall move $a0, $t1 li $v0, syscall li $a0, 32 li $v0, 11 syscall move $a0,... bne $s0,$0,L1 j Next1 L1: move $t3,$t0 move $t0,$t1 move $t1,$t3 Next1: slt $s0,$t2,$t0 bne $s0,$0,L2 j Next2 L2: move $t3,$t0 move $t0,$t2 move $t2,$t3 Next2: slt $s0,$t2,$t1 bne $s0,$0,L3 j Next3

Ngày đăng: 10/05/2021, 23:22

TỪ KHÓA LIÊN QUAN

w