• Tidak ada hasil yang ditemukan

lecture 04 machine language

N/A
N/A
Protected

Academic year: 2017

Membagikan "lecture 04 machine language"

Copied!
18
0
0

Teks penuh

(1)

www.nand2tetris.org

(2)

Where we are at:

Chapters 10 - 11

VM Translator

(3)

Machine language

!

"

(4)

Binary and symbolic notation

&

'

#

#

$

( )

%

1010 0001 0010 1011

1010 0001 0010 1011

ADD R1, R2, R3

ADD R1, R2, R3

*+,*

(5)

Lecture plan

/ 0

#

"

'

(6)

Typical machine language commands

(a small sample)

// In what follows R1,R2,R3 are registers, PC is program counter,

// and addr is some value.

ADD R1,R2,R3 // R1

R2 + R3

ADDI R1,R2,addr // R1

R2 + addr

AND R1,R1,R2 // R1

R1 and R2 (bit-wise)

JMP addr // PC

addr

JEQ R1,R2,addr

// IF R1 == R2 THEN PC

addr ELSE PC++

LOAD R1, addr // R1

RAM[addr]

STORE R1, addr // RAM[addr]

R1

NOP // Do nothing

// Etc. – some 50-300 command variants

// In what follows R1,R2,R3 are registers, PC is program counter,

// and addr is some value.

ADD R1,R2,R3 // R1

R2 + R3

ADDI R1,R2,addr // R1

R2 + addr

AND R1,R1,R2 // R1

R1 and R2 (bit-wise)

JMP addr // PC

addr

JEQ R1,R2,addr

// IF R1 == R2 THEN PC

addr ELSE PC++

LOAD R1, addr // R1

RAM[addr]

STORE R1, addr // RAM[addr]

R1

NOP // Do nothing

(7)

The Hack computer

*1

2

RAM

)

3

ROM

)

(

D

4

A, M,

M

RAM[A]

'

ALU,

'

PC,

5

ROM

)

*1

4

4

,% 6

$

(8)

The A-instruction

@value

// A

value

@value

// A

value

7

%

8

&

A

=

value

@17 // A = 17

D = A // D = 17

@17 // A = 17

D = A // D = 17

5

$

@17 // A = 17

D = M // D = RAM[17]

@17 // A = 17

D = M // D = RAM[17]

#

RAM

register

=

RAM[A]

@17 // A = 17

JMP // fetch the instruction

// stored in ROM[17]

@17 // A = 17

JMP // fetch the instruction

// stored in ROM[17]

#

ROM

(9)

The C-instruction

(first approximation)

&$

3

0

/ 0

#

D

A-1

#

A

D

A + 1

#

D

19

#

A

D

A + D

#

RAM[5034]

D - 1

#

RAM[53]

171

1

RAM[7],

D

.

dest

=

x

+

y

dest

=

x

-

y

dest

=

x

dest

= 0

dest

= 1

dest

= -1

dest

=

x

+

y

dest

=

x

-

y

dest

=

x

dest

= 0

dest

= 1

dest

= -1

x

=

{A

4

D

4

M}

y

=

{A

4

D

4

M

4

1}

(10)
(11)

Control

(focus on the yellow chips only)

A

L

U

M

u

x

D

A/M

a

-bit

D register

A register

A

M

RAM

(selected

register)

ROM

(selected

register)

PC

Instruction

3

/ 0

ROM

'

)

*1

4

ROM[0]

5

ROM[PC]

address

input

(12)

Coding examples

(practice)

&$

3

0

/ 0

goto 50

if D==0 goto 112

if D<9 goto 507

if RAM[12] > 0 goto 50

if sum>0 goto END

if x[i]<=0 goto NEXT.

sum 2200

// are optional

Where:

// are optional

(13)

if condition {

code block 1}

else {

code block 2}

code block 3

if condition {

code block 1}

else {

code block 2}

code block 3

/

D

not condition

@IF_TRUE

D;JEQ

code block 2

@END

0;JMP

(IF_TRUE)

code block 1

(END)

code block 3

D

not condition

@IF_TRUE

D;JEQ

code block 2

@END

0;JMP

(IF_TRUE)

code block 1

(END)

code block 3

/ 0

IF logic – Hack style

/ 0

*

(14)

WHILE logic – Hack style

while condition {

code block 1

}

Code block 2

while condition {

code block 1

}

Code block 2

/

(LOOP)

D

not condition)

@END

D;JEQ

code block 1

@LOOP

0;JMP

(END)

code block 2

(LOOP)

D

not condition)

@END

D;JEQ

code block 1

@LOOP

0;JMP

(END)

code block 2

/ 0

/ 0

*

(15)

Side note

(focus on the yellow chip parts only)

A

L

U

M

u

x

D

A/M

a

-bit

D register

A register

A

M

RAM

(selected

register)

ROM

(selected

register)

PC

Instruction

address

input

address

input

3

/ 0

4

A

(

(> 4

%

5

0

@addr

D=M;someJumpDirective

0

"

/ 0

4

C

(16)
(17)

Symbols in Hack assembly programs

// Typical symbolic

// Hack code, meaning

// not important

@R0

// Typical symbolic

// Hack code, meaning

// not important

(18)

Perspective

/ 0

8

$

D=D+A

ADD D,D,A

/ 0

@I

A

(

A

(

4

)

C

Referensi

Dokumen terkait

of this project is to control and monitor in load utilization by using Programmable Logic.. Controller (PLC) via Human-machine Interface

Perancangan kontrol rumah cerdas berbasis PLC ( Programmable Logic controller) dengan SCADA ( Supervisory Control And Data Acquisition ) sebagai HMI ( Human Machine Interface

Perancangan kontrol rumah cerdas berbasis PLC ( Programmable Logic controller) dengan SCADA ( Supervisory Control And Data Acquisition ) sebagai HMI ( Human Machine Interface

Perancangan kontrol rumah cerdas berbasis PLC ( Programmable Logic controller) dengan SCADA ( Supervisory Control And Data Acquisition ) sebagai HMI ( Human Machine Interface

Selesai mengikuti matakuliah ini, mahasiswa diharapkan mampu menjelaskan konsep human machine interface, menghubungkan kontroler (PLC) dengan perangkat lunak HMI,

PENGUJIAN KELAYAKAN MEDIA PEMBELAJARAN PROGRAMMABLE LOGIC CONTROLLER YANG TERINTEGRASI HUMAN MACHINE INTERFACE.. Universitas Pendidikan Indonesia | repository.upi.edu

PENGUJIAN KELAYAKAN MEDIA PEMBELAJARAN PROGRAMMABLE LOGIC CONTROLLER YANG TERINTEGRASI HUMAN MACHINE INTERFACE.. Universitas Pendidikan Indonesia | repository.upi.edu

PENGUJIAN KELAYAKAN MEDIA PEMBELAJARAN PROGRAMMABLE LOGIC CONTROLLER YANG TERINTEGRASI HUMAN MACHINE INTERFACE.. Universitas Pendidikan Indonesia | repository.upi.edu