Download presentation
Presentation is loading. Please wait.
1
CPS120: Introduction to Computer Science
Low-Level Programming Languages Nell Dale • John Lewis
2
Bits, Bytes and Characters
Bytes are frequently used to hold individual characters in a text document. In the ASCII character set, each binary value between 0 and 127 is given a specific character. Most computers extend the ASCII character set to use the full range of 256 characters available in a byte. The upper 128 characters handle special things like accented characters from common foreign languages
3
ASCII Each byte contains not a letter but a number -- the number is the ASCII code corresponding to the character (see below). So on disk, the numbers for the file look like this: F o u r a n d s e v e n By looking in the ASCII table, you can see a one-to-one correspondence between each character and the ASCII code used. Note the use of 32 for a space is the ASCII code for a space. We could expand these decimal numbers out to binary numbers (so 32 = ) if we wanted to be technically correct -- that is how the computer really deals with things.
4
What the Computer Can Do
Store, retrieve and process are actions that the computer can take on data
5
Computer Operations A computer is a programmable electronic device that can store, retrieve, and process data Data and instructions to manipulate the data are logically the same and can be stored in the same place Store, retrieve, and process are actions that the computer can perform on data
6
Machine Language Machine language: the instructions built into the hardware of a particular computer Machine specific
7
Machine Language Every processor type has its own set of specific machine instructions The relationship between the processor and the instructions it can carry out is completely integrated Each machine-language instruction does only one very low-level task
8
Pep/7: A Virtual Computer
A virtual computer is a hypothetical machine designed to contain the important features of real computers that we want to illustrated We are only going to examine a few of these instructions
9
Features in Pep/7 Pep/7 has 32 machine-language instructions
The memory unit is made up of 4,096 bytes of storage ( decimal) The word length in Pep/7 is 16 bits Pep/7 has seven registers, four of which we focus on at this point The program counter (PC) (contains the address of the next instruction to be executed) The instruction register (IR) (contains a copy of the instruction being executed) The index register (X register) – holds data The accumulator (A register) – holds data Can be downloaded from
10
Features in Pep/7 Pep/7’s architecture
11
Instruction Format There are two parts to an instruction
The 8-bit instruction specifier (1rst byte) Indicates the operation to be carried out And optionally, the 16-bit operand specifier (2nd and 3rd bytes) Holds the operand itself or an address The Pep/7 instruction format
12
Instruction Format The instruction specifier is made up of several sections The operation code The register specifier 0 for A; 1 for X The addressing-mode specifier 00 immediate mode – last two bytes have operand 01 direct mode – last two bytes contain an address
13
Instruction Format The operation code specifies which instruction is to be carried out The 1-bit register specifier is 0 if register A (the accumulator) is involved in the operation and 1 if register X (the index register) is involved The 2-bit addressing-mode specifier says how to interpret the operand part of the instruction
14
Instruction Format Difference between immediate-mode and direct-mode addressing
15
Some Sample Instructions
Subset of Pep/7 instructions
16
A Program Example Let’s write "Hello" on the screen
17
Pep/7 Simulator A program that behaves just like the Pep/7 virtual machine behaves To run a program, we enter the hexadecimal code, byte by byte with blanks between each
18
Assembly Language Assembly languages: assign mnemonic letter codes to each machine-language instruction The programmer uses these letter codes in place of binary digits A program called an assembler reads each of the instructions in mnemonic form and translates it into the machine-language equivalent
19
Hello -- Assembly CHARO C#H/ J; Output 'H' CHARO C#e/ J; Output 'e'
CHARO C#l/ J; Output 'l' CHARO C#o/ J; Output 'o' STOP END
20
Pep/7 Assembly Language
21
Figure 7.5 Assembly Process
22
A New Program
23
Our Completed Program
24
Testing Test plan: a document that specifies how many times and with what data the program must be run in order to thoroughly test the program A code-coverage approach designs test cases to ensure that each statement in the program is executed Data-coverage testing is another approach; it designs test cases to ensure that the limits of the allowable data are covered
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.