First Foray into Programming (the hard way)
A reminder from last lesson: A machine code instruction has two parts: Op-code Operand An instruction set is a list of all the Op- Codes, such as: Load Add Store
Machine Code Machine code is a series of 1s and 0s We can easily encode our instruction – each instruction has a binary representation. Op-Code (4 bit)Machine Operation 0000Load from memory 0001Load operand value 0100Add from memory 0101Add operand value 1000Store into memory
Representing a full instruction One instruction is 16 bits (how many bytes?) long. This is our word size. The first 4 bits are the op-code, the rest is the operand. QUESTION - How many memory locations can be addressed?
Machine Code vs Assembly vs Load #23 Add 2 Store 65 This is a 1-to-1 mapping
Questions Using a 2 byte word with a 4-bit op-code, write the following in machine code: Load 76 Add #43 Add 90 Store 12 Load #45 Write the following in assembly language:
Hexadecimal Hex is the base-16 number system, the 16 digits are: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F Sometimes A-F are in lower case A3 = 10*16^2 + 3*16 = 10* *16 = = D = 6*16^2 + 13*16 = 6* *16 = = 1744
Hexadecimal (2) Each 4-bit binary number can be represented by one hex digit. Write the following in hex: Load 76 Add #43 Add 90
Homework Create a program that does something involving all 5 op codes. Write this in assembly using a 2-byte word. Convert this into machine code in denary Finally, write this in hexadecimal.