decjmpreg ebx,L3 inc edx L3: eax

Session 4: Atomic Language.
Take Turing Machine
Look back to 1st session’s work on
hardware, RISC and CISC registerbased machines.
Also look forward to next week’s work
on Software, computer programming
languages.
4
2
1
1
2
4
a2 a1 a0 s b0 b1 b2
m
n
q
(s,m,n,q)
(s*,m*,n*,q*)
4
2
1
1
2
4
4
2
1
1
2
4
a2 a1 a0 s b0 b1 b2
m
n
q
(s,m,n,q)
(s’,m’,n’,q’)
8
4
2
1
0
1
1
0
m
2
4
8
1
1
1
0
n
q
(s,m,n) = ( , , )
1
8
4
2
1
0
1
1
0
1
m
1
2
4
1
1
0
n
q
(s*,m*,n*) = ( , , )
8
8
4
2
1
0
1
1
1
m
2
4
8
0
1
1
0
n
q
(s,m,n) = ( , , )
1
8
4
2
1
0
1
1
1
0
m
1
2
4
1
1
0
n
q
(s*,m*,n*) = ( , , )
8
s*  rem( n / 2)
m*  s  2m
n*  n / 2
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
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
inc ecx
inc ecx
L1:
assume ecx is zero
…
…
decjmpreg ecx,L1
e e e e
a b c d
x x x x
L3:
L4:
mov ecx,3
mov eax,0
mov ebx,0
decjmpreg ecx,L4
inc ebx
jmp L3
nop
e e e e
a b c d
x x x x
e e e e
a b c d
x x x x
e e e e
a b c d
x x x x
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
ecx
ebx
eax
m
s
n
m
s
ALU
n
z
m
s
ALU
n
z
z = 2m
z=z+s
s*  rem( n / 2)
m* = z
m*  s  2m
z = n/2
n*  n / 2
s* = rem(n/2)
n=z
e e e e
a b c d
x x x x
L3:
L4:
mov ecx,5
mov eax,0
mov ebx,0
decjmpreg ecx,L4
inc ebx
decjmpreg ecx,L4
inc eax
jmp L3
hlt
e e e e
a b c d
x x x x
e e e e
a b c d
x x x x
e e e e
a b c d
x x x x
e e e e
a b c d
x x x x
L3:
L4:
mov ecx,5
mov eax,0
mov ebx,0
decjmpreg ecx,L4
inc ebx
decjmpreg ecx,L4
inc eax
jmp L3
hlt
e e e e
a b c d
x x x x
e e e e
a b c d
x x x x
5
0
0
0
4
2
1
1
3
1
0
1
1
2
0
e e e e
a b c d
x x x x
L3:
L4:
mov ecx,3
mov eax,0
decjmpreg ecx,L4
inc eax
inc eax
jmp L3
hlt
e e e e
a b c d
x x x x
e e e e
a b c d
x x x x
e e e e
a b c d
x x x x
e e e e
a b c d
x x x x
L3:
L4:
mov ecx,3
mov eax,0
decjmpreg ecx,L4
inc eax
jmp L3
hlt
e e e e
a b c d
x x x x
e e e e
a b c d
x x x x
e e e e
a b c d
x x x x
mov reg,0
inc reg
decjmpz L
jmp L
e e e e
a b c d
x x x x
L3:
L4:
mov ecx,3
mov ebx,0
decjmpreg ecx,L4
inc ebx
inc ebx
jmp L3
hlt
e e e e
a b c d
x x x x
e e e e
a b c d
x x x x
e e e e
a b c d
x x x x
e e e e
a b c d
x x x x
L3:
L4:
mov ecx,3
mov ebx,0
decjmpreg ecx,L4
inc ebx
inc ebx
jmp L3
hlt
e e e e
a b c d
x x x x
e e e e
a b c d
x x x x
3
0
2
1
0
1
3
5
2
4
6
e e e e
a b c d
x x x x
L1:
L2
…
…
decjmpreg ecx,L2
jmp L1
…
e e e e
a b c d
x x x x
e e e e
a b c d
x x x x
3
2
1
0
L2:
decjmpreg eax,L1
inc edx
z = 2m
inc edx
jmp L2
L1:
decjmpreg ebx,L3
inc edx
L3:
L4:
L6:
L7:
decjmpreg edx,L4
inc eax
jmp L3
mov ebx,0
decjmpreg ecx,L6
inc ebx
decjmpreg ecx,L6
inc edx
jmp L4
decjmpreg edx,L7
inc ecx
jmp L6
hlt
eax holds m
ebx holds s
ecx holds n
edx holds z
If s is 1 z = z + 1
m* = z
s* = rem(n/2)
z = n/2 whole
n* = z
1
2 4
8
1
rem
2
4 8
whole
8
4
2
1
8
4
2 1
decjmpreg ebx,L3
inc edx
L3:
eax
ebx
ecx
edx
holds m
holds s
holds n
holds z
8
4
2
1
0
1
1
0
m
1
2
4
8
1
1
1
0
n
s
8
4
2
1
1 0
1
1
1
m
1
2
4
8
0
0
0
1
n
s
8
4
2
1
1 0
1
1
1
1
2
4
8
0
0
0
1
m
n
s
; 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
y
2
x
1
Head
move
left code
Head
move
right 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
e e e e
a b c d
x x x x
mov eax,3
inc eax
inc ebx
e e e e
a b c d
x x x x
e e e e
a b c d
x x x x
e e e e
a b c d
x x x x
e e e e
a b c d
x x x x
L1:
L2:
mov ecx,2
decjmpreg ecx,L2
jmp L1
hlt
e e e e
a b c d
x x x x
e e e e
a b c d
x x x x
e e e e
a b c d
x x x x
e e e e
a b c d
x x x x
L1:
L2:
mov eax,0
mov ecx,2
decjmpreg ecx,L2
inc eax
jmp L1
hlt
e e e e
a b c d
x x x x
e e e e
a b c d
x x x x
e e e e
a b c d
x x x x
State
Even
Current
State S
read the symbol s
Symbol
read s
store s
Symbol
to write
s*
Directio
n
to
move d
New
state S*
if(s == 0), set s = 0 and
jmp to move-right code
Even
0
0
R
Even
Even
1
0
R
Odd
if(s == 1), set s = 0 and
jmp to move-right code
Even
@
0
N
Halt
Code for
read-write
head move
left
Code for
read-write
head move
right
use the stored s
if(s == 0), jump to the
even state code
if(s == 1), jump to the
odd state code
8 4 2
1
0
1
1
1
1 2
4 8
1
1 0
1
8 4 2 1
1 2
4 8
e e e e
a b c d
x x x x
e e e e
a b c d
x x x x
e e e e
a b c d
x x x x
e e e e
a b c d
x x x x