Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 7: Low-Level Programming Languages Chapter 7 Low-Level Programming Languages Page 66 In order to execute instructions on a CPU, those instructions.

Similar presentations


Presentation on theme: "Chapter 7: Low-Level Programming Languages Chapter 7 Low-Level Programming Languages Page 66 In order to execute instructions on a CPU, those instructions."— Presentation transcript:

1

2 Chapter 7: Low-Level Programming Languages Chapter 7 Low-Level Programming Languages Page 66 In order to execute instructions on a CPU, those instructions must be in the particular binary format that was designed for that CPU. The set of instructions available for a particular CPU is known as its machine language. Sample Machine Instruction Format Op-Code Field (specifies the operation to be performed) Operand Field (gives further details pertinent to the operation)

3 Simplified Machine Language Chapter 7 Low-Level Programming Languages Page 67 Note that every instruction is sixteen bits (four hexadecimal digits) in length.

4 Sample Program Chapter 7 Low-Level Programming Languages Page 68 205CLoad register 0 with the integer 92 (hexadecimal 5C) 300EStore the contents of register 0 at main memory address 0E 205ALoad register 0 with the integer 90 (hexadecimal 5A) 300FStore the contents of register 0 at main memory address 0F 110ELoad register 1 with the bit pattern at main memory address 0E 120FLoad register 2 with the bit pattern at main memory address 0F 5012Add the contents of registers 1 & 2 and put the sum in register 0 300DStore the contents of register 0 at memory address 0D C000Halt execution In an advanced language, like C++, this program would be: void main() { int X, Y, Z; int X, Y, Z; X = 92; X = 92; Y = 90; Y = 90; Z = X + Y; Z = X + Y;}

5 Another Sample Program Chapter 7 Low-Level Programming Languages Page 69 How would we code this pseudocode with our machine language? Procedure negative (x) If x < 0 If x < 0 Then return 1 Then return 1 Else return 0 Else return 0 We’ll assume that the value of x has already been stored in main memory at address 5A, that the returned value (0 or 1) will be placed at address 5B, and that the program itself will be stored starting at address D0.

6 Chapter 7 Low-Level Programming Languages Page 70 Procedure negative (x) If x < 0 If x < 0 Then return 1 Then return 1 Else return 0 Else return 0 Let’s take advantage of the fact that if an 8- bit two’s- complement number is ANDed with 10000000, the result is 00000000 if the number is positive, and 10000000 if the number is negative.

7 Chapter 7 Low-Level Programming Languages Page 71 To make programming easier to handle, special languages (unique to the kinds of computers running them) have been developed. Machine Language Feature Corresponding Assembly Language Feature Hexadecimal Op-Codes Mnemonic Operators (“LOADVAR”, “JUMPEQ”, etc.) Data In Specific Main Memory Locations User-Defined Variable Names (“X”, “RESULT”) Instruction Addresses In Main Memory User-Defined Instruction Labels (“NEGATIVE”, “STOREIT”) Programs written in such an assembly language are executed by first passing through a special program (called an assembler) that translates the assembly language code into machine language. Assembly Language Example : LOADVAR R1,X LOADVAR R1,X LOADHEX R0,80 LOADHEX R0,80 AND R2,R0,R1 AND R2,R0,R1 JUMPEQ R0,R2,NEGATIVE JUMPEQ R0,R2,NEGATIVE LOADHEX R3,00 LOADHEX R3,00 JUMPEQ R0,R0,STOREIT JUMPEQ R0,R0,STOREIT NEGATIVE LOADHEX R3,01 STOREIT STORE R3, RESULT HALT HALT

8 Chapter 7 Low-Level Programming Languages Page 72 While assembly languages are easier to use than machine languages, they still share two big problems with machine languages. Assembly Language Problems 1. Assembly languages are still machine-dependent. A program written in one machine’s assembly language cannot be executed on a computer with a different instruction set and register configuration. 2. Assembly language programming is still too nitpicky. Programmers are forced to concentrate on the tiny details necessary to choreograph the computer’s activity, instead of focusing on the overall solution of the problem being tackled. overall solution of the problem being tackled.


Download ppt "Chapter 7: Low-Level Programming Languages Chapter 7 Low-Level Programming Languages Page 66 In order to execute instructions on a CPU, those instructions."

Similar presentations


Ads by Google