Low-Level Programming: Machine Language, Pep/8 Assembly, and Algorithms

Classified in Computers

Written on in English with a size of 3.92 KB

Computer Fundamentals and Data

A Computer is a programmable electronic device that can store, retrieve, and process data.

Data and Instructions: Instructions that manipulate data are logically the same as the data itself and can be stored in the same memory location.

Understanding Machine Language

Machine Language is a language made up of binary-coded instructions built directly into the computer's hardware and used by the processor.

Why Machine Language?

It is the fundamental language the hardware understands (no choice).

Characteristics of Machine Language

  • Every processor has its own unique set of machine instructions.
  • The relationship between the processor and the instructions it can carry out is completely integrated.
  • Each machine-language instruction performs only one very low-level task.

Components of a Machine Instruction

  • Operation Code (Opcode): Specifies which instruction is to be carried out.
  • Register Specifier: Specifies which register is to be used (e.g., only register A in this context).
  • Addressing-Mode Specifier: Dictates how the operand part of the instruction should be interpreted.

Pep/8 Simulator and Assembly Programming

Pep/8 Simulator

A program that behaves exactly like the Pep/8 virtual machine.

Running a Program in Pep/8

To execute a program, enter the hexadecimal code byte by byte, separated by spaces.

Assembly Language

A language that uses mnemonic codes to represent machine-language instructions.

Assembler

A program that reads instructions in mnemonic form and translates them into machine language.

Pep/8 Assembly Language Examples

Program 1: Outputting "Hello"

CHARO 0x0048,I; Output an 'H'
CHARO 0x0065,I; Output an 'e'
CHARO 0x006C,I; Output an 'l'
CHARO 0x006C,I; Output an 'l'
CHARO 0x006F,I; Output an 'o'
STOP
.END

Program 2: Read, Sum, and Print Three Values

(Manual implementation)

BR main
sum: .WORD 0x0000
num1: .BLOCK 2
num2: .BLOCK 2
num3: .BLOCK 2
Main:
    LDA sum,d   ; Load accumulator with initial sum (0)
    DECI num1,d ; Read num1
    ADDA num1,d ; Add num1
    DECI num2,d ; Read num2
    ADDA num2,d ; Add num2
    DECI num3,d ; Read num3
    ADDA num3,d ; Add num3
    STA sum,d   ; Store final sum
    DECO sum,d  ; Output the sum
    STOP
.END

Algorithms and Structured Logic

Algorithm for Preparing Hollandaise Sauce

IF concerned about cholesterol THEN
    Put butter substitute in a pot
ELSE
    Put butter in a pot
END IF

Turn on burner
Put pot on the burner

WHILE (Pot is Not bubbling) DO
    Leave pot on the burner
END WHILE

Put other ingredients in the blender
Turn on blender

WHILE (More contents in pot) DO
    Pour contents into blender in slow stream
END WHILE

Turn off blender

Defining Pseudocode

Pseudocode is a way of expressing algorithms that uses a mixture of English phrases and indentation to make the steps in the solution explicit.

  • There are generally no strict grammar rules in pseudocode.
  • Pseudocode is typically not case sensitive.

Pseudocode Example: Base Conversion

Algorithm for converting a decimal number to a new base:

WHILE (the quotient is not zero) DO
    Divide the decimal number by the new base.
    Make the remainder the next digit to the left in the answer.
    Replace the original decimal number with the quotient.
END WHILE

Example Calculation: Converting 93 to Base 8

Applying the algorithm:

  1. 93 / 8 = 11, remainder 5
  2. 11 / 8 = 1, remainder 3
  3. 1 / 8 = 0, remainder 1

Reading the remainders from bottom to top yields the answer: 1358.

Related entries: