MIPS组装中的虚拟点机器人

在该项目中,编写了MIPS Assembly程序以在给定环境中移动虚拟点机器人。 

将提供环境的尺寸,机器人的起始坐标,障碍物的位置和移动命令。程序应根据给定的命令,环境尺寸和障碍物坐标移动机器人。在程序结束时,应显示机器人的最终坐标。 

以下是输入示例: 
3x5#(1,2)#(0,4),(2,3)#ACCAGGGACEEEFFDB#
3x5是所提供环境的尺寸。
(1,2)是机器人的初始坐标。
(0,4)和(2,3)是障碍物的坐标。
#是分隔输入部分的字符。

虚拟点机器人的技巧
虚拟演示示例环境


正如我们在环境的虚拟表示中看到的那样,显示了移动命令(A,B,C,D,E,F,G和H)的方向。 
机器人的预期最终坐标为(2,2)。
当程序接收到移动命令时,它将检查下一个位置是否有障碍物。如果在下一个位置检测到障碍物,则程序应忽略移动命令。否则,程序将根据移动命令移动机器人。

以下是虚拟点机器人的MIPS汇编代码:

############################################
####### A virtual point robot ##############
############################################
.data 
input: .space 201 # save the logic expression 
size_envir: .space 201 # save the dimensions of environment
start_coordinate: .space 201    # save the start_coordinate of robot
obstacles: .space 201 # save all coordinates of obstacles
result: .asciiz "("
sign1:  .asciiz ","
sign2:  .asciiz ")"
.text #enables text input / output, kind of like String.h in C++
#########################################
###############  Main ###################
######################################### 
main: 
la $a0,input  #input for logic expression to get dimensions of environment, starting coordinates...
li $a1,201
li $v0,8
syscall  # get the logic expression from the console
la $a1,size_envir # save the dimensions of environment
xori $s0,$a0,0x00
xori $s1,$a1,0x00
lb $t1, 0($s0) 
sb $t1,0($s1) 
lb $t1, 2($s0) 
sb $t1,1($s1) 
la $a1,start_coordinate # save the starting coordinates of robot
xori $s0,$a0,0x00
xori $s1,$a1,0x00
lb $t1, 5($s0) 
sb $t1,0($s1) 
lb $t1, 7($s0) 
sb $t1,1($s1) 
lb $t6,0($s1) # save x-coordinate of robot
lb $t7,1($s1) # save y-coordinate of robot
la $a1,obstacles # save the coordinates of obstacles
xori $s0,$a0,0x00
xori $s1,$a1,0x00
lb $t1, 11($s0) 
sb $t1,0($s1) 
lb $t1, 13($s0) 
sb $t1,1($s1) 
addi $a0,$a0,9
addi $a1,$a1,1
check_obstables: # check next obstacles
addi $a0,$a0,6
xori $s0,$a0,0x00
lb $t1,0($s0)
addi $t2,$zero,35 # detect the "#" character to know whether or not there is no next obstacles.
addi $t3,$zero,44 # detect the "," character
xori $t4,$s0,0x00
beq $t1,$t2,move_command # perform move commands
beq $t1,$t3,next_obstacles # check next obstacles 
li $v0,10  # code for exit 
syscall   # exit program 
########################################################
next_obstacles:
addi $t4,$t4,2
xori $s0,$t4,0
lb $t1,0($s0)
addi $a1,$a1,1
xori $s1,$a1,0x00
sb $t1,0($s1)
addi $a1,$a1,1
xori $s1,$a1,0x00
addi $s0,$s0,2
lb $t1,0($s0)
sb $t1,0($s1)
j check_obstables
######################################################
move_command: 
la $a3,obstacles
subu $t5,$a1,$a3
#addi $t5,$t5,1 # $t5 is the number of obstacles
#######################################################
move_doing: # do the move commands
addi $a0,$a0,1 # next move command
xori $s0,$a0,0x00
lb $t1,0($s0)
addi $t2,$zero,35 
beq $t1,$t2,finish # if the command is #, finish the program. otherwise, move on the command
#####################################################
# Continue to do the command
#####################################################
xori $t2,$zero,0x41 # "A" command
beq $t1,$t2,A_command 
xori $t2,$zero,0x42 # "B" command
beq $t1,$t2,B_command
xori $t2,$zero,0x43 # "C" command
beq $t1,$t2,C_command 
xori $t2,$zero,0x44 # "D" command
beq $t1,$t2,D_command 
xori $t2,$zero,0x45 # "E" command
beq $t1,$t2,E_command 
xori $t2,$zero,0x46 # "F" command
beq $t1,$t2,F_command 
xori $t2,$zero,0x47 # "G" command
beq $t1,$t2,G_command 
xori $t2,$zero,0x48 # "H" command
beq $t1,$t2,H_command 
li $v0,10  # code for exit 
syscall   # exit program 
A_command: 
    xori $t1,$t6,0x00
    xori $t2,$t7,0x00
    addi $t2,$t2,1
    addi $t4,$t5,0
    j check_border 
B_command: 
    xori $t1,$t6,0x00
    xori $t2,$t7,0x00
    addi $t2,$t2,1
    addi $t1,$t1,1
    addi $t4,$t5,0
    j check_border 
C_command: 
    xori $t1,$t6,0x00
    xori $t2,$t7,0x00
    addi $t1,$t1,0x01
    addi $t4,$t5,0
    j check_border 
D_command: 
    xori $t1,$t6,0x00
    xori $t2,$t7,0x00
    addi $t1,$t1,0x01
    xori $t3,$zero,0x01
    sub $t2,$t2,$t3
    addi $t4,$t5,0
    j check_border 
E_command: 
    xori $t1,$t6,0x00
    xori $t2,$t7,0x00
    xori $t3,$zero,0x01
    sub $t2,$t2,$t3
    addi $t4,$t5,0
    j check_border 
F_command: 
    xori $t1,$t6,0x00
    xori $t2,$t7,0x00
    xori $t3,$zero,0x01
    sub $t2,$t2,$t3
    sub $t1,$t1,$t3
    addi $t4,$t5,0
    j check_border 
G_command: 
    xori $t1,$t6,0x00
    xori $t2,$t7,0x00
    xori $t3,$zero,0x01
    sub $t1,$t1,$t3
    addi $t4,$t5,0
    j check_border 
H_command: 
    xori $t1,$t6,0x00
    xori $t2,$t7,0x00
    xori $t3,$zero,0x01
    sub $t1,$t1,$t3
    addi $t2,$t2,1
    addi $t4,$t5,0
    j check_border 
check:  #t4 is the number of obstacles
 #t1: x new
 #t2: y new
 la $a3,obstacles
 add $s0,$a3,$t4
 lb $t3,0($s0)
 beq $t3,$t2,keep_1
 xori $t3,$zero,0x01
 sub $t4,$t4,$t3
 j next_check
keep_1: xori $t3,$zero,0x01
 sub $t4,$t4,$t3
 la $a3,obstacles
 add $s0,$a3,$t4
 lb $t3,0($s0)
 beq $t3,$t1,keep_position
 j next_check
next_check: 
 xori $t3,$zero,0x01
 sub $t4,$t4,$t3
 bltz $t4,update_robot
 j check
#########################################
check_border: 
 xori $t3,$zero,48
 blt $t1,$t3,keep_position
 xori $t3,$zero,48
 blt $t2,$t3,keep_position
 la $a3, size_envir
 xori $s0,$a3,0x00
 lb $t3,0($s0)
 beq $t1,$t3,keep_position 
 xori $s0,$a3,0x00 
 lb $t3,1($s0) 
 beq $t2,$t3,keep_position 
 j check
#########################################
update_robot: addi $t6,$t1,0 # x-coordinate
 addi $t7,$t2,0  # y-coordinate
 j move_doing 
#########################################
keep_position:  
 j move_doing
#########################################
finish: # finish all the command and output the final coordinate of robot
li $v0, 4       # $system call code for print_str
la $a0, result     # $address of string to print
syscall         # print the string
li $v0, 1       # $system call code for print_int
xori $t1,$zero,48
subu $t6,$t6,$t1
xori $a0,$t6,0x00       # $integer to print
syscall         # print it
li $v0, 4       # $system call code for print_str
la $a0, sign1     # $address of string to print
syscall
li $v0, 1       # $system call code for print_int
xori $t1,$zero,48
subu $t7,$t7,$t1
xori $a0,$t7,0x00       # $integer to print
syscall
li $v0, 4       # $system call code for print_str
la $a0, sign2     # $address of string to print
syscall
li $v0,10  # code for exit 
syscall   # exit program 
##########################################
该程序在Qtspim上进行了验证,并获得了机器人的正确最终坐标,如下图所示。

虚拟点机器人的技巧
程序结果

您可能会这样:

您可能还会喜欢:
D触发器的VHDL代码
D触发器的Verilog代码
比较器的Verilog代码
FIFO存储器的Verilog代码
FIFO存储器的VHDL代码
FPGA Verilog VHDL课程

没意见:

发表评论

热门FPGA项目