Chapter07 - Chapter 7: Low-Level Programming Languages...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Chapter 7: Low-Level Programming Languages Languages In order to execute instructions on a CPU, those instructions In must be in the particular binary format that was designed for that set of instructions available for a that The CPU. The particular CPU is known as its machine language. language Sample Machine Instruction Format Op-Code Field Operand Field (specifies the (specifies operation to be performed) performed) (gives further details (gives pertinent to the operation) operation) Chapter 7 Low-Level Low-Level Programming Languages Languages Page 1 Page Simplified Machine Language Simplified Note that every instruction is sixteen bits (four hexadecimal digits) in Note length. length. Chapter 7 Low-Level Low-Level Programming Languages Languages Page 2 Page Sample Program Sample 205C 300E 205A 300F 110E 120F 5012 300D C000 Load register 0 with the integer 92 (hexadecimal 5C) Store the contents of register 0 at main memory address 0E Load register 0 with the integer 90 (hexadecimal 5A) Store the contents of register 0 at main memory address 0F Load register 1 with the bit pattern at main memory address 0E Load register 2 with the bit pattern at main memory address 0F Add the contents of registers 1 & 2 and put the sum in register Add Store the contents of register 0 at memory address 0D 0 Halt execution In an advanced In language, like C++, this program would be: program void main() { int X, Y, Z; int X = 92; 92; Y = 90; 90; Z = X + Y; Y; } Chapter 7 Low-Level Low-Level Programming Languages Languages Page 3 Page Another Sample Program Another How would we code this pseudocode with our machine How language? language? We’ll assume that the value of x has Procedure negative We’ll Procedure already been stored in main memory (x ) at address 5A, that the returned value If x < 0 (0 or 1) will be placed at address 5B, Then return and that the program itself will be 1 stored starting at address D0. stored Else return 0 Else Chapter 7 Low-Level Low-Level Programming Languages Languages Page 4 Page Let’s take Let’s advantage of the fact that if an 8that bit two’scompleme nt number nt is ANDed with 10000000, the result is 00000000 if the number is positive, and 10000000 if the number is negative. is Procedure negative Procedure (x) If x < 0 Then return 1 Then Else return 0 Else Chapter 7 Chapter Low-Level Low-Level Programming Languages Languages Page 5 Page Assembly Language To make programming easier to handle, special languages (unique to To the kinds of computers running them) have been developed. the Programs written in such an assembly language are executed by first Programs assembly passing through a special program (called an assembler) that translates the assembly language code into machine language. the Example: LOADVAR R1,X LOADVAR LOADHEX LOADHEX AND AND JUMPEQ JUMPEQ LOADHEX LOADHEX JUMPEQ JUMPEQ NEGATIVE LOADHEX STOREIT STORE HALT HALT R0,80 R2,R0,R1 R0,R2,NEGATIVE R3,00 R0,R0,STOREIT R3,01 R3, RESULT Machine Language Machine Feature Feature Corresponding Assembly Language Corresponding Feature Feature Hexadecimal Op-Codes Data In Specific Main Memory Data Locations Locations Instruction Addresses In Main Instruction Memory Memory Mnemonic Operators (“LOADVAR”, “JUMPEQ”, etc.) User-Defined Variable Names (“X”, “RESULT”) User-Defined Instruction Labels (“NEGATIVE”, User-Defined “STOREIT”) “STOREIT”) Chapter 7 Chapter Low-Level Low-Level Programming Languages Languages Page 6 Page Assembly Language Problems While assembly languages are easier to use than machine languages, While they still share two big problems with machine languages. they 1. Assembly languages are still machinedependent. 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 2. nitpicky. 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 Chapter 7 Chapter Low-Level Low-Level Programming Languages Languages Page 7 Page ...
View Full Document

This note was uploaded on 08/26/2009 for the course CS 111 taught by Professor Klein,s during the Fall '08 term at Southern Illinois University Edwardsville.

Ask a homework question - tutors are online