0% found this document useful (0 votes)
25 views15 pages

Laboratory Exercise 10

Uploaded by

phuc.nh225903
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views15 pages

Laboratory Exercise 10

Uploaded by

phuc.nh225903
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Laboratory Exercise 10

Method to control peripheral devices via simulators.


Họ tên: Dương Công Thuyết MSSV: 20225932

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 1 = doan b; ...

# Bit 7 = dau .

.eqv SEVENSEG_RIGHT 0xFFFF0010 # Dia chi cua den led 7 doan phai

.text

main:
li $a0, 0x06 # set value for segments

jal SHOW_7SEG_LEFT # show

nop

li $a0, 0x66 # set value for segments

jal SHOW_7SEG_RIGHT # show

nop
exit:

li $v0, 10

syscall

endmain:

#---------------------------------------------------------------

# Function SHOW_7SEG_LEFT : turn on/off the 7seg

# param[in] $a0 value to shown


# remark $t0 changed

#---------------------------------------------------------------
SHOW_7SEG_LEFT:

li $t0, SEVENSEG_LEFT # assign port's address

sb $a0, 0($t0) # assign new value

nop

jr $ra

nop

#---------------------------------------------------------------

# Function SHOW_7SEG_RIGHT : turn on/off the 7seg


# param[in] $a0 value to shown

# remark $t0 changed

#---------------------------------------------------------------

SHOW_7SEG_RIGHT:

li $t0, SEVENSEG_RIGHT # assign port's address

sb $a0, 0($t0) # assign new value

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

Write a program to make the led count from 0->9->0


Code:
.eqv SEVENSEG_LEFT 0xFFFF0011

.eqv SEVENSEG_RIGHT 0xFFFF0010

.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:

lbu $a0, 0($t3)

jal SHOW_7SEG_LEFT

nop

jal SHOW_7SEG_RIGHT

nop

addiu $t1, $t1, 1

addiu $t3, $t3, 1

blt $t1, $t2, count_up

count_down:

lbu $a0, 0($t3)


jal SHOW_7SEG_LEFT
nop

jal SHOW_7SEG_RIGHT
nop

addiu $t1, $t1, -1

addiu $t3, $t3, -1

bge $t1, $zero, count_down

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:

lui $t0, 0x00FF

ori $t0, $t0, 0x0000

li $t1, 7

li $t2, 6

li $t3, 15

li $t4, 14
draw_square:

move $a0, $t0

move $a1, $t1

jal draw_square_at_position

move $a1, $t2

jal draw_square_at_position

move $a1, $t3

jal draw_square_at_position
move $a1, $t4

jal draw_square_at_position

li $a0, 0

addiu $a1, $t1, 1

jal draw_square_at_position

addiu $a1, $t2, 1

jal draw_square_at_position

addiu $a1, $t3, 1

jal draw_square_at_position

addiu $a1, $t4, 1

jal draw_square_at_position

addiu $t1, $t1, -1


addiu $t2, $t2, -1
addiu $t3, $t3, -1

addiu $t4, $t4, -1

beq $t1, 1, draw_red_then_black_and_reset

beq $t2, 0, draw_red_then_black_and_reset

beq $t3, 9, draw_red_then_black_and_reset

beq $t4, 8, draw_red_then_black_and_reset


j draw_square

nop

draw_red_then_black_and_reset:

move $a0, $t0

move $a1, $t1

jal draw_square_at_position
move $a1, $t2

jal draw_square_at_position

move $a1, $t3

jal draw_square_at_position

move $a1, $t4

jal draw_square_at_position

li $a0, 0

move $a1, $t1

jal draw_square_at_position

move $a1, $t2

jal draw_square_at_position

move $a1, $t3

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:

sll $t5, $a1, 2

add $t5, $t5, MONITOR_SCREEN

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:

.eqv HEADING 0xffff8010

.eqv MOVING 0xffff8050

.eqv LEAVETRACK 0xffff8020

.eqv WHEREX 0xffff8030

.eqv WHEREY 0xffff8040

.text

main:

centering:

addi $a0, $0, 120


jal ROTATE

jal GO

sleep:

addi $v0, $0, 32

li $a0, 20000
syscall

draw:
jal loop
end_main:

li $v0,10

syscall

loop:

#first time

jal TRACK

addi $a0, $0, 150


jal ROTATE

jal GO

addi $v0, $0, 32

li $a0, 10000

syscall

jal UNTRACK

jal TRACK

jal TRACK

addi $a0, $0, 270

jal ROTATE

jal GO

addi $v0, $0, 32

li $a0, 5000
syscall
jal UNTRACK

jal TRACK

jal TRACK

addi $a0, $0, 0

jal ROTATE

jal GO
addi $v0, $0, 32

li $a0, 8800

syscall

jal STOP

jal UNTRACK

jr $ra

GO:

li $at, MOVING # change MOVING port


addi $k0, $zero,1 # to logic 1,

sb $k0, 0($at) # to start running

nop

jr $ra

nop

STOP:

li $at, MOVING # change MOVING port to 0

sb $zero, 0($at) # to stop

nop

jr $ra

nop

TRACK:

li $at, LEAVETRACK # change LEAVETRACK port

addi $k0, $zero,1 # to logic 1,


sb $k0, 0($at) # to start tracking
nop

jr $ra

nop

UNTRACK:

li $at, LEAVETRACK # change LEAVETRACK port to 0

sb $zero, 0($at) # to stop drawing tail

nop
jr $ra

nop

ROTATE:

li $at, HEADING # change HEADING port

sw $a0, 0($at) # to rotate robot

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

.eqv KEY_READY 0xFFFF0000

.eqv DISPLAY_CODE 0xFFFF000C

.eqv DISPLAY_READY 0xFFFF0008

.text

li $k0, KEY_CODE

li $k1, KEY_READY

li $s0, DISPLAY_CODE
li $s1, DISPLAY_READY

loop: nop

WaitForKey: lw $t1, 0($k1)

nop

beq $t1, $zero, WaitForKey

ReadKey: lw $t0, 0($k0)

nop

WaitForDis: lw $t2, 0($s1)

nop

beq $t2, $zero, WaitForDis

nop

beq $t6, 0, checke

beq $t6, 1, checkx

beq $t6, 2, checki


beq $t6, 3, checkt
checke: beq $t0, 101, checkexit

checkx: beq $t0, 120, checkexit

checki: beq $t0, 105, checkexit

checkt: beq $t0, 116, checkexit

Encrypt: li $t6, 0

s1: j check1

s2: j check2
s3: j check3

s4: j check4

s5:

ShowKey: sw $t0, 0($s0)

nop

j loop

check1:

li $t3, 0
blt $t0, 65, s2

bgt $t0, 90, s2

addi $t0, $t0, 32

li $t3, 1

j s5

check2:

li $t4, 0

blt $t0, 97, s3

bgt $t0, 122, s3

subi $t0, $t0, 32

li $t4, 1

j s5

check3:

li $t5, 0
blt $t0, 48, s4
bgt $t0, 57, s4

addu $t0, $0, $t0

li $t5, 1

j s5

check4:

beq $t3,1,s5

beq $t4,1,s5
beq $t5,1,s5

j s5

checkexit:

addi $t6, $t6, 1

beq $t6,4, end_main

j s1

end_main:

li $v0, 10
syscall

Result:

You might also like