Session 4: Atomic Language. Take Turing Machine Look back to 1 st session’s work on hardware, RISC and CISC register- based machines. Also look forward to next week’s work on Software, computer programming languages.
S1 ? ? S2 S1 S2 Sn
S1 ? ?
ax eax rax
q s mn (s,m,n,q)(s*,m*,n*,q*)
q s mn (s,m,n,q)(s’,m’,n’,q’)
s mn (s,m,n) = (,, )
s* m*n* (s*,m*,n*) = (,, )
s mn (s,m,n) = (,, )
s* m*n* (s*,m*,n*) = (,, )
mov reg,0 Put 0 into register “reg” inc reg Add 1 to the contents of register “reg” decjmpreg reg,lab If register “reg” is zero, jump to the label “lab” else subtract 1 from “reg” and do the next instruction jmp lab Jump straight to the label “lab” hlt Halt
inc reg Add 1 to the contents of register “reg” decjmpreg reg,lab If register “reg” is zero, jump to the label “lab” else subtract 1 from “reg” and do the next instruction
assume ecx is zero inc ecx assume ecx is zero L1:… … decjmpreg ecx,L1
mov ecx,3 mov eax,0 mov ebx,0 L3:decjmpreg ecx,L4 inc ebx jmp L3 L4:nop eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx
mov eax,0 inc eax hlt eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx
mov ecx,3 decjmpreg ecx,L1 L1: hlt eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx
mov ecx,3 L2: decjmpreg ecx,L1 jmp L2 L1: hlt eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx
is S = q? read line inc line pointer end of Table? end (error) is “read” = s? inc line pointer move left/right write in cell Current state readwritemove L / R New state write in cell end of Table? end (error)
main PROC mov ecx,N mov eax,0 l1:mov ebx,0 decjmpz l2 inc ebx decjmpz l2 inc eax jmp l1 l2:hlt main ENDP ecxebxeax
m s n z ALU smn
m s n z z = 2m z = z + s m* = z s* = rem(n/2) n = z z = n/2
mov ecx,5 mov eax,0 L3:mov ebx,0 decjmpreg ecx,L4 inc ebx decjmpreg ecx,L4 inc eax jmp L3 L4:hlt eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx
mov ecx,5 mov eax,0 L3:mov ebx,0 decjmpreg ecx,L4 inc ebx decjmpreg ecx,L4 inc eax jmp L3 L4:hlt eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx 0 0 1
mov ecx,3 mov eax,0 L3:decjmpreg ecx,L4 inc eax jmp L3 L4:hlt eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx
mov eax,3 mov edx,0 L3:decjmpreg eax,L4 inc edx jmp L3 L4:hlt eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx
mov ecx,3 L3:mov eax,0 decjmpreg ecx,L4 inc eax jmp L3 L4:hlt eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx
mov reg,0 inc reg decjmpz L jmp L
mov ecx,3 mov ebx,0 L3:decjmpreg ecx,L4 inc ebx jmp L3 L4:hlt eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx
mov ecx,3 mov ebx,0 L3:decjmpreg ecx,L4 inc ebx jmp L3 L4:hlt eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx 0 5 6
… L1:decjmpreg ecx,L2 jmp L1 L2… eaxeax ebxebx ecxecx edxedx 3 2 eaxeax ebxebx ecxecx edxedx 1 eaxeax ebxebx ecxecx edxedx 0
L2:decjmpreg eax,L1 inc edx jmp L2 L1:decjmpreg ebx,L3 inc edx L3:decjmpreg edx,L4 inc eax jmp L3 L4:mov ebx,0 decjmpreg ecx,L6 inc ebx decjmpreg ecx,L6 inc edx jmp L4 L6:decjmpreg edx,L7 inc ecx jmp L6 L7:hlt eax holds m ebx holds s ecx holds n edx holds z If s is 1 z = z + 1 z = 2m m* = z s* = rem(n/2) z = n/2 whole n* = z
remwhole
decjmpreg ebx,L3 inc edx L3:
eax holds m ebx holds s ecx holds n edx holds z
s mn
s mn
s mn
; get current state ; read current symbol s. (Read ebx) ; get new state using value of s (in ebx) ; write new symbol.(Write to ebx) ; get the movement direction ; execute the movement code (left or right)
; assume we start in state 0 ; write the starting symbol into ebx ; write the code for move right or move left ; write the new symbol into ebx ; jump to the new state code ; repeat lines 2 to 4
The movement code (left or right) depending on the state
1 2 x y
Head move right code Head move left code
read the symbol s store s if(s == 0), set s = 0 and jmp to move-right code if(s == 1), set s = 0 and jmp to move-right code use the stored s if(s == 0), jump to the even state code if(s == 1), jump to the odd state code
mov eax,3 inc eax inc ebx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx
mov ecx,2 L1:decjmpreg ecx,L2 jmp L1 L2:hlt eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx
mov eax,0 mov ecx,2 L1:decjmpreg ecx,L2 inc eax jmp L1 L2:hlt eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx
read the symbol s store s if(s == 0), set s = 0 and jmp to move-right code if(s == 1), set s = 0 and jmp to move-right code use the stored s if(s == 0), jump to the even state code if(s == 1), jump to the odd state code Code for read-write head move left Code for read-write head move right Current State S Symbol read s Symbol to write s* Directio n to move d New state S* Even00R 10ROdd State Even
eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx
Turing Machine Table Tape t R/W Head