Download presentation
Presentation is loading. Please wait.
Published byDiana Merritt Modified over 9 years ago
1
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.
2
S1 ? ? S2 S1 S2 Sn
3
S1 ? ?
4
ax eax rax
5
q s mn 4 2 11 2 4 (s,m,n,q)(s*,m*,n*,q*)
6
4 2 11 2 4
7
q s mn 4 2 11 2 4 (s,m,n,q)(s’,m’,n’,q’)
8
s mn 8 4 2 11 2 4 8 01101110 (s,m,n) = (,, )
9
s* m*n* 8 4 2 11 2 4 8 01101110 (s*,m*,n*) = (,, )
10
s mn 8 4 2 11 2 4 8 01110110 (s,m,n) = (,, )
11
s* m*n* 8 4 2 11 2 4 8 01110110 (s*,m*,n*) = (,, )
13
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
14
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
15
assume ecx is zero inc ecx assume ecx is zero L1:… … decjmpreg ecx,L1
16
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
17
mov eax,0 inc eax hlt eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx
18
mov ecx,3 decjmpreg ecx,L1 L1: hlt eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx
19
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
20
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)
21
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
22
m s n z ALU smn
23
m s n z z = 2m z = z + s m* = z s* = rem(n/2) n = z z = n/2
24
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
25
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 5 0 0 4 1 3 1 eaxeax ebxebx ecxecx edxedx 0 2 1 1 2 eaxeax ebxebx ecxecx edxedx 0 0 1
26
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
27
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
28
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
29
mov reg,0 inc reg decjmpz L jmp L
36
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
37
mov ecx,3 mov ebx,0 L3:decjmpreg ecx,L4 inc ebx jmp L3 L4:hlt eaxeax ebxebx ecxecx edxedx 3 0 2 1 2 eaxeax ebxebx ecxecx edxedx 1 3 4 eaxeax ebxebx ecxecx edxedx 0 5 6
38
… L1:decjmpreg ecx,L2 jmp L1 L2… eaxeax ebxebx ecxecx edxedx 3 2 eaxeax ebxebx ecxecx edxedx 1 eaxeax ebxebx ecxecx edxedx 0
39
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
40
remwhole 1 2 4 8 8 4 2 1
42
decjmpreg ebx,L3 inc edx L3:
43
eax holds m ebx holds s ecx holds n edx holds z
44
s mn 8 4 2 11 2 4 8 01101110
45
s mn 8 4 2 11 2 4 8 01110001 1
46
s mn 8 4 2 11 2 4 8 01110001 1
47
; 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)
48
; 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
49
The movement code (left or right) depending on the state
50
1 2 x y
51
Head move right code Head move left code
52
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
53
mov eax,3 inc eax inc ebx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx
54
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
55
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
56
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 Even@0NHalt State Even
57
0111 8 4 2 1 0111 111110 1 2 4 8
58
eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx eaxeax ebxebx ecxecx edxedx
59
Turing Machine Table Tape t R/W Head
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.