Docsity

Understanding Assembly and Machine Language: A Comparison, Exams of Computer Architecture and Organization

Partial preview of the text

Download Understanding Assembly and Machine Language: A Comparison and more Exams Computer Architecture and Organization in PDF only on Docsity!

Assembly language:

sto 0 1 – rcl 0 7 –

  • // type in particular value for x rcl 0 // execute program to compute y 11 – / g rtn
  • Memory used to store program
  • Memory is addressed
  • May compute memory addresses – unlike registers
  • Registers may be selected – not indexed

struct registers { int r0, r1, r2, r3, r4, r5, r6, r7, r8, r9; }

Machine language:

  • Program stored using machine language – key codes
  • Central processing unit (CPU) executes the codes
  • Program counter (PC) holds address of next instruction to be executed

Assembly language vs. machine language:

Address M/C code Keys Comment 000 44 0 sto 0 store in r 002 1 1 enter 1 003 30 - subtract 004 45 0 rcl 0 r0 to stack 006 7 7 enter 7 007 30 - subtract 008 20 * multiply 009 45 0 rcl 0 r0 to stack 011 1 1 enter 1 012 1 1 make it 11 013 30 - subtract 014 10 / divide 015 43 32 g rtn return to calc. mode

  • Calculator mode – codes (m/c lang.) sent to ALU

call it by: cat(a , b , c)

then get: a b c

define(sto, 44 0) then sto always refers to r

define(sto, ’44 $1’) then call it as sto(0)

Conditionals & Branching

  • Testing and branching – requires targets
  • Targets of branches are labels referring to memory locations
  • Need to add memory address for instructions
  • Use location counter – memory address of instruction being executed

define(f, 42) define(g, 43) define(loc, 0) define(sto, ‘loc: 44 $1 define(‘loc’, eval(loc + 2))’) define(rcl, ‘loc: 45 $1 define(‘loc’, eval(loc + 2))’)

define(div, ‘loc: 10 define(‘loc’, eval(loc + 1))’) define(mul, ‘loc: 20 define(‘loc’, eval(loc + 1))’)

define(label, ‘define($1, loc)’) define(ifeq, ‘loc g 20 define(‘loc’, eval(loc + 2))’) define(gto, ‘loc 22 $1 define(‘loc’, eval(loc + 2))’)

ifeq -- test if current value = -- if 0, execute next instruction -- else skip next instruction

gto -- argument is a label -- assign value of argument to PC (target)

Program to execute equation in a loop:

label(c) digit(7) rtn sub label(a) mul digit(0) rcl(x_r) sto(x_r) digit(1) label(b) digit(1) rcl(x_r) sub digit(1) div digit(1) pse

store (results); } while (instruction != halt);

Stack Machine

  • Stack architecture does not have registers
  • Use memory to place items onto stack
  • Use load and store operations for moving data between memory and the stack
  • Must specify memory address
  • MAR – memory address register
  • MDR – memory data register
  • IR – instruction register holds fetched instruction
  • ALU uses top two elements on the stack for all computations

Load Store Machines

  • Initially memory limited to few hundred words
  • Access time to all locations was the same
  • As memory size increased time vs. cost issue arose
  • New designs included variable access times
  • Register file – high speed memory
  • Use load and store instructions between registers and memory
  • ALU would function on registers only
  • Register file replaces the stack of the stack machine
  • SPARC architecture is a load/store machine
  • A symbol followed by a colon defines the symbol to have as its value the current value of the location counter
  • The symbol is called a label

define(y_r, r0) define(x_r, r1) define(a2_r, r2) define(a1_r, r3) define(a0_r, r4) define(temp_r, r5)

start: mov 0, %x_r mov a2, %a2_r mov a1, %a1_r mov a0, %a0_r sub %x_r, %a2_r, %y_r sub %x_r, %a1_r, %temp_r mul %y_r, %temp_r, %y_r sub %x_r, %a0_r, %temp_r div %y_r, %temp_r, %y_r