Laboratory Exercise 10
Laboratory Exercise 10
Assignment 1:
Create a new project, type in, and build the program of Home Assignment 1.
Show different values on LED. Write a program to make the led count from 0->9->0
Code:
.eqv SEVENSEG_LEFT 0xFFFF0011 # Dia chi cua den led 7 doan trai.
# Bit 0 = doan a;
# Bit 7 = dau .
.eqv SEVENSEG_RIGHT 0xFFFF0010 # Dia chi cua den led 7 doan phai
.text
main:
li $a0, 0x06 # set value for segments
nop
nop
exit:
li $v0, 10
syscall
endmain:
#---------------------------------------------------------------
#---------------------------------------------------------------
SHOW_7SEG_LEFT:
nop
jr $ra
nop
#---------------------------------------------------------------
#---------------------------------------------------------------
SHOW_7SEG_RIGHT:
nop
jr $ra
nop
Result:
Explain:
- Mã HEX của các số từ 0 đến 9 là: 0 = 3F, 1 = 06, 2 = 5B, 3 = 4F, 4=66, 5=6D, 6=7D,
7=07, 8=7F, 9=6F
- 7SEG_LEFT để hiển thị chữ số bên trái, 7SEG_RIGHT để hiển thị chữ số bên phải
- Theo thứ tự thì $a0 = 0x06, $a0 = 0x66 => Result = 14
.data
SEG_CODES: .byte 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F
.text
main:
la $t3, SEG_CODES
li $t1, 0x0
li $t2, 0x9
count_up:
jal SHOW_7SEG_LEFT
nop
jal SHOW_7SEG_RIGHT
nop
count_down:
jal SHOW_7SEG_RIGHT
nop
endmain:
SHOW_7SEG_LEFT:
li $t0, SEVENSEG_LEFT
sb $a0, 0($t0)
nop
jr $ra
nop
SHOW_7SEG_RIGHT:
li $t0, SEVENSEG_RIGHT
sb $a0, 0($t0)
nop
jr $ra
nop
Assignment 2:
Create a new project, type in, and build the program of Home Assignment 2.
Draw something. Write a program to draw a red square, and moving the square from right to
left.
Code:
.eqv MONITOR_SCREEN 0x10010000 #Dia chi bat dau cua bo nho man hinh
.eqv red 0x00FF0000 #Cac gia tri mau thuong su dung
.eqv green 0x0000FF00
.eqv blue 0x000000FF
.eqv white 0x00FFFFFF
.eqv YELLOW 0x00FFFF00
.text
li $k0, MONITOR_SCREEN
li $t1, 16
li $t0, white
loop_white:
sw $t0, 0($k0)
nop
addiu $k0, $k0, 4
addiu $t1, $t1, -1
bgtz $t1, loop_white
nop
li $t1, 24
li $t0, blue
loop_blue:
sw $t0, 0($k0)
nop
addiu $k0, $k0, 4
addiu $t1, $t1, -1
bgtz $t1, loop_blue
nop
li $t1, 24
li $t0, red
loop_red:
sw $t0, 0($k0)
nop
addiu $k0, $k0, 4
addiu $t1, $t1, -1
bgtz $t1, loop_red
nop
Result:
Explain:
- Tạo vòng lặp để in từng màu với chỉ số chạy của trắng là 16 (8 ô x 2 dòng), xanh và đỏ là
24 (8 ô x 3 dòng)
Write a program to draw a red square, and moving the square from right to left.
Code:
.eqv MONITOR_SCREEN 0x10010000
.text
.globl main
main:
li $t1, 7
li $t2, 6
li $t3, 15
li $t4, 14
draw_square:
jal draw_square_at_position
jal draw_square_at_position
jal draw_square_at_position
move $a1, $t4
jal draw_square_at_position
li $a0, 0
jal draw_square_at_position
jal draw_square_at_position
jal draw_square_at_position
jal draw_square_at_position
nop
draw_red_then_black_and_reset:
jal draw_square_at_position
move $a1, $t2
jal draw_square_at_position
jal draw_square_at_position
jal draw_square_at_position
li $a0, 0
jal draw_square_at_position
jal draw_square_at_position
jal draw_square_at_position
move $a1, $t4
jal draw_square_at_position
li $t1, 7
li $t2, 6
li $t3, 15
li $t4, 14
j draw_square
nop
draw_square_at_position:
sw $a0, 0($t5)
jr $ra
Assignment 3:
Create a new project, type in, and build the program of Home Assignment 3.
Make the Bot run and draw a triangle by tracking and redraw the 1st triangle.
Code:
.text
main:
centering:
jal GO
sleep:
li $a0, 20000
syscall
draw:
jal loop
end_main:
li $v0,10
syscall
loop:
#first time
jal TRACK
jal GO
li $a0, 10000
syscall
jal UNTRACK
jal TRACK
jal TRACK
jal ROTATE
jal GO
li $a0, 5000
syscall
jal UNTRACK
jal TRACK
jal TRACK
jal ROTATE
jal GO
addi $v0, $0, 32
li $a0, 8800
syscall
jal STOP
jal UNTRACK
jr $ra
GO:
nop
jr $ra
nop
STOP:
nop
jr $ra
nop
TRACK:
jr $ra
nop
UNTRACK:
nop
jr $ra
nop
ROTATE:
nop
jr $ra
nop
Result:
Assignment 4:
Create a new project, type in, and build the program of Home Assignment 4.
Read key char and terminate the application when receiving “exit” command.
Code:
.eqv KEY_CODE 0xFFFF0004
.text
li $k0, KEY_CODE
li $k1, KEY_READY
li $s0, DISPLAY_CODE
li $s1, DISPLAY_READY
loop: nop
nop
nop
nop
nop
Encrypt: li $t6, 0
s1: j check1
s2: j check2
s3: j check3
s4: j check4
s5:
nop
j loop
check1:
li $t3, 0
blt $t0, 65, s2
li $t3, 1
j s5
check2:
li $t4, 0
li $t4, 1
j s5
check3:
li $t5, 0
blt $t0, 48, s4
bgt $t0, 57, s4
li $t5, 1
j s5
check4:
beq $t3,1,s5
beq $t4,1,s5
beq $t5,1,s5
j s5
checkexit:
j s1
end_main:
li $v0, 10
syscall
Result: