02 Linguaggio Macchina e Assembly [PDF]

  • 0 0 0
  • Gefällt Ihnen dieses papier und der download? Sie können Ihre eigene PDF-Datei in wenigen Minuten kostenlos online veröffentlichen! Anmelden
Datei wird geladen, bitte warten...
Zitiervorschau

FONDAMENTI DI INFORMATICA Prof. PIER LUCA MONTESSORO Università degli Studi di Udine

Linguaggio macchina e linguaggio assembly

Formato delle istruzioni 15

8

gruppo modo di indirizzamento codice dell’istruzione

7

0

primo registro (se presente)

secondo registro (se presente)

In alternativa può contenere un “offset” scritto su 8 bit per le istruzioni di salto

Gruppi • Trasferimento dati da e verso la memoria o tra registri codice 0 (002)

• Istruzioni aritmetico-logiche codice 1 (012)

• Input/output

codice 2 (102)

• Istruzioni di controllo codice 3 (112)

Modi di indirizzamento • Operando immediato – codice 1 (012), mnemonico I: la parola che segue l’istruzione contiene il dato

• Indirizzo assoluto – codice 2 (102), mnemonico A: la parola che segue l’istruzione contiene l’indirizzo del dato

• Indirizzo in registro – codice 3 (112), mnemonico R: l’indirizzo del dato è contenuto nel registro specificato

Gruppo “trasferimento dati” LDWI d X load word 00010000dddd0000 DATA(16) LDWA d A load word 00100000dddd0000 ADDR(16) LDWR d a load word 00110000ddddaaaa LDBI d X load byte 00010001dddd0000 DATA(8) LDBA d A load byte 00100001dddd0000 ADDR(16) LDBR d a load byte 00110001ddddaaaa STWA s A store word 00100010ssss0000 ADDR(16) STWR s a store word 00110010ssssaaaa STBA s A store byte 00100011ssss0000 ADDR(16) STBR s a store byte 00110011ssssaaaa MV s d move 00000100ssssdddd PUSH s push 00001000ssss0000 POP d pop 00001001dddd0000 SPRD d read SP 00001101dddd0000 SPWR s write SP 00001110ssss0000 s, d, a: codice del registro interessato (s = source, d = destination, a = address)

Esempio LDWI R15 ABAC

indirizzo di memoria

0000 0001 0002 0003

F0 10 AC AB

registro 15

codice operativo

operando

Gruppo “aritmetico-logiche” ADD SUB NOT AND OR XOR INC DEC LSH RSH

s s r s s s r r r r

d d d d d

add subtract bitwise NOT bitwise AND bitwise OR bitwise XOR increment decrement left shift right shift

01000000ssssdddd 01000001ssssdddd 01000010rrrr0000 01000011ssssdddd 01000100ssssdddd 01000101ssssdddd 01001000rrrr0000 01001001rrrr0000 01001010rrrr0000 01001011rrrr0000

s, d, r: codice del registro interessato (s = source, d = destination)

Esempio SUB R8 R10 registro R8

indirizzo di memoria

0000 0001

8A 41

registro R10

codice operativo

Gruppo “input/output” INW INB OUTW OUTB TSTI TSTO

d d s s A A

A A A A

input word input byte out word out byte test input test output

10000000dddd0000 10000001dddd0000 10000010ssss0000 10000011ssss0000 1000010000000000 1000010100000000

IN_ADDR IN_ADDR OUT_ADDR OUT_ADDR IN_ADDR OUT_ADDR

TSTI e TSTO settano il flag Z a 1 (vero) se l’operazione di I/O è stata completata; se il flag vale zero l’operazione di I/O va ripetuta

Gruppo “controllo” BR JMP JMPZ JMPNZ JMPN JMPNN JMPC JMPV CALL RET HLT

A f f f f f f f A

branch jump jump if zero jump if not zero jump if negative jump if not neg. jump if carry jump if overflow subroutine call return from sub. halt

1100000000000000 ADDR 11000001ffffffff 11000010ffffffff 11000011ffffffff 11000100ffffffff 11000101ffffffff 11000110ffffffff 11000111ffffffff 1100100000000000 ADDR 1100100100000000 1100111100000000

ffffffff = valore dell’offset di salto (8 bit in complemento a 2)

CALL e RET • Fanno uso dello stack di sistema (tipo di dato astratto LIFO: Last-In-First-Out implementato mediante vettore) • Analogia con una pila (“stack”) di piatti: si inserisce in cima alla pila e si preleva in ordine inverso a quello dell’inserimento • Operazioni – PUSH (inserisce) – POP (preleva)

Stack di sistema PUSH

stack pointer

punta sempre alla prima posizione libera dello stack

POP

Esempio POP  A75B

PUSH (A75B)

SP = 2

22 68

7 6 5 4 3 2 1 0

SP = 4

5B A7 22 68

7 6 5 4 3 2 1 0

SP = 2

22 68

7 6 5 4 3 2 1 0

Riepilogo linguaggio

- In the following, uppercase symbols mean numbers, lowercase symbols mean registers. For example, 'A' could be 0x32F5, 'a' could be R12 - 'r', 's', 'd', and 'a' represent the code (0 to 15) of the register to be used: r = register (the value in the register will be read and modified) s = source (read only) d = destination (the value in the register will overwritten) a = (the value in the register will be used as a memory address) - The ffffffff value represents a memory offset, positive (forward branches) or negative (in 2's complement, for backword branches) - Most of the instructions of the data trasfer group work on memory data, addresses or registers: xxxI = data is stored in memory in the location immediately following the instruction code xxxA = the instrucion code in memory is followed by the data address xxxR = two registers are used: one to sore the data, and another one to store the memory address

Riepilogo linguaggio

Data transfer group: ____________________ assembly

inst. name

machine code

LDWI LDWA LDWR LDBI LDBA LDBR STWA STWR STBA STBR MV PUSH POP SPRD SPWR

load word load word load word load byte load byte load byte store word store word store byte store byte move push pop read SP write SP

00010000dddd0000 00100000dddd0000 00110000ddddaaaa 00010001dddd0000 00100001dddd0000 00110001ddddaaaa 00100010ssss0000 00110010ssssaaaa 00100011ssss0000 00110011ssssaaaa 00000100ssssdddd 00001000ssss0000 00001001dddd0000 00001101ssss0000 00001110ssss0000

d d d d d d s s s s s s d d s

X A a X A a A a A a d

action DATA(16) ADDR(16) DATA(8) ADDR(16) ADDR(16) ADDR(16)

d