So I got this “Design a Turing machine, implement basic operations of TM in MIPS using MARS assembler” in my COAL’s assignment.
I have a basic idea of TM and can perform basic arithmetic operations but I am not sure how to implement them in Assembly.
Can someone guide how can I kickstart this project and how can I implements the below functionalities in mips?
- addition using TM
- subtraction using TM
- multiplication using TM
- TM for 1’s and 2’s complement
Any help would be highly appreciated..
So far, By using the instructions from GEEKS for GEEKS, I’ve written the below code for addition but it’s not generating the correct output and I am not sure why.
.data
tape: .asciiz “11111c11″ #input tape for the Turing machine
blank: .asciiz ” ” #blank symbol
head: .word 0 #head position
state: .asciiz “start” #initial state
result_message: .asciiz “resulting tape: “
.text
.globl main
main:
la $t0, tape
li $t1, 0 #initializing head position to 0
la $t2, state
li $t3, ‘X’
li $t4, ‘0’
li $t5, ‘c’
li $t6, ‘ ‘ #loading blank character into $t6
li $t8, 0 #initializing counter to detect the end of the tape
start:
lb $t7, 0($t0) #load the current symbol at the head position
beq $t7, $t5, step_3 # If symbol is ‘c’, go to step_3
beq $t7, $t4, convert_to_X # If symbol is ‘0’, convert to ‘X’
j move_right # Otherwise, move right
convert_to_X:
sb $t3, 0($t0) # Convert ‘0’ to ‘X’
addi $t0, $t0, 1 # Move the head right
j move_right
move_right:
lb $t7, 0($t0) # Load the current symbol at the new head position
beq $t7, $t5, step_3 # If symbol is ‘c’, go to step_3
beq $t7, $zero, end # If we reach the end of the tape, go to end
addi $t0, $t0, 1 # Move the head right
j move_right
step_3:
lb $t7, 0($t0) # Load the current symbol at the head position
beq $t7, $t6, convert_to_0 # If symbol is blank, convert to ‘0’
addi $t0, $t0, 1 # Move the head right
j step_3
convert_to_0:
sb $t4, 0($t0) # Convert blank to ‘0’
addi $t0, $t0, -1 # Move the head left
j move_left
move_left:
lb $t7, 0($t0) # Load the current symbol at the new head position
beq $t7, $t5, check_next # If symbol is ‘c’, check the next
beq $t7, $t3, start # If symbol is ‘X’, go back to start
addi $t0, $t0, -1 # Move the head left
j move_left
check_next:
addi $t0, $t0, 1 # Move the head right to skip ‘c’
lb $t7, 0($t0) # Load the current symbol at the new head position
beq $t7, $zero, end # If symbol is null, end
sb $t6, -1($t0) # Convert ‘c’ to blank
j start
end:
# Print the resulting tape
la $a0, result_message
li $v0, 4
syscall
la $a0, tape
li $v0, 4
syscall
# End the program
li $v0, 10
syscall
For ex, in the above code I am trying to add 5 + 2 (tape: .asciiz “11111c11” #input tape for the Turing machine). The output snapshot is pasted below;
enter image description here
Iqra Usman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.