Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Understanding Low-Level Languages: Features, Mnemonics, and Symbolic Addressing, Study notes of Programming Languages

An overview of low-level languages, focusing on the features, mnemonics, and symbolic addressing in assembly language. Low-level languages are CPU specific and use mnemonics for programming, with an instruction set consisting of various mnemonics for arithmetic, data transfer, logic, and jump operations. Symbolic addressing is used to define symbols for data items or locations, making the software more understandable and relocatable in memory.

What you will learn

  • What are mnemonics and how are they used in assembly language?
  • What are the features of low-level languages?
  • What is symbolic addressing and how does it improve programming?
  • What is the role of opcodes and operands in assembly language?
  • What is a low-level language and how does it differ from machine code?

Typology: Study notes

2021/2022

Uploaded on 09/27/2022

uzmaan
uzmaan 🇺🇸

3.1

(9)

216 documents

1 / 20

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
F453 Module 8: Low Level Languages
8.2: Features of
Low-Level
Languages
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download Understanding Low-Level Languages: Features, Mnemonics, and Symbolic Addressing and more Study notes Programming Languages in PDF only on Docsity!

F453 Module 8: Low Level Languages

8.2: Features of

Low-Level

Languages

What this module is about

  • In this module we discuss:

a. explain the concepts and, using examples, demonstrate

an understanding of the use of the accumulator,

registers, and program counter;

b. describe immediate, direct, indirect, relative and indexed

addressing of memory when referring to low-level

languages;

c. discuss the concepts and, using examples, show

an understanding of mnemonics, opcode,

operand and symbolic addressing in assembly

language to include simple arithmetic operations,

data transfer and flow-control.

Low-Level Languages

  • Some features of Low Level languages include
    • They are CPU specific, making direct use of internal registers
    • 'Mnemonics' are used as programming code such as MOV or ADD
    • Many different memory modes can be used (previous presentation)
    • Labels are used as reference points to allow the code to jump from one part to another.
  • Advantages
    • Low level languages allow for close control of the CPU, for example many device drivers are coded in assembly language.
    • They can be very efficient. Well-optimised code written in a low level language can be made to run very quickly compared to other programming paradigms.
  • Disadvantages
    • They are difficult to use as the programming commands can be quite obscure
    • A good assembly language programmer needs to know a lot of detail about the internal structure of the CPU - e.g.its registers and memory management methods
    • Low level languages produce the least portable source code.
  • Assembly language looks like this:
    1. .MODEL SMALL;
    2. .STACK;
    3. .CODE;
    4. mov ah,1h; moves the value 1h to register ah
    5. mov cx,07h;moves the value 07h to register cx
    6. int 10h;

Mnemonics

  • The registers within a CPU store and process binary data. In theory the programmer could load data and instructions directly into the registers in pure binary, like this: - 10110000 00110010
  • This instructs a Intel 8086 processor to load 32 into its accumulator. Difficult to remember!
  • A slightly easier way of coding this would be to code the same instruction in hexadecimal. Like this: - B0 32
  • This is ' machine code ' and it is difficult to program at this level and yet retain an understanding of what the software is doing. So the CPU chip makers supply a set of Mnemonics for the programmer to use with their processors.
  • Mnemonics are a set of programming instructions that are later translated into pure machine code by a piece of software called an ' assembler '.
  • For example the machine code above in mnemonic form looks like:
    • MOV AL, 32h
  • This makes more sense to the programmer. You can see that the command is instructing the CPU to load 32 hex immediately into a register called AL.

Opcodes and Operands

  • An opcode is short for ' Operation Code '.
  • An opcode is a single instruction that can be executed by the CPU. In machine language it is a binary or hexadecimal value such as 'B6' loaded into the instruction register.
  • In assembly language mnemonic form an opcode is a command such as MOV or ADD or JMP.
  • For example
    • MOV, AL, 34h
  • The opcode is the MOV instruction. The other parts are called the ' operands '.
  • Operands are manipulated by the opcode. In this example, the operands are the register named AL and the value 34 hex.

Symbolic addressing

• Another key aspect of programming is to fetch or store

data and instructions from memory.

• The simplest way to do this is to refer directly to a

memory location such as #3001. But this brings a

number of problems (remember last presentation)

  • it is difficult to see the meaning of the data in location #
  • the data may not be able to be located at #3001 because another program is already using that location.

• To overcome this issue, the idea of 'symbolic addressing'

is used. Instead of referring to an absolute location, the

assembly language allows you to define a 'symbol' for

the data item or location.

Symbolic addressing

• The advantages of using symbolic addressing

over direct memory references are:

– The program is re-locatable in memory. It does not

particularly care about its absolute location, it will still

work

– Using symbols makes the software much more

understandable

• When the code is ready to be loaded and run, a

' symbol table ' is created by the assembler for

the linker and loader to use to place the

software into memory.

Arithmetic operations

  • Any software language needs to support the basic functions of a

running program and a low level language is no different.

  • It must be able to support the basic arithmetic operations of

adding, subtracting, multiplying and dividing.

  • These operations are determined by a set of fairly self-evident

mnemonics.

Logic operations

  • As well as the usual arithmetic operations, a CPU will also be

performing logic operations.

  • These logical operations will also set or reset a number of flags in

the Program Status Word (PSW) depending on the outcome. These

flags can then be tested to cause a branch or a jump in the code to

occur.

Jumps and branching

  • Most programs need to run code that is dependent on the

outcome of some test within the software, this is called 'branching'.

  • Common programming forms include loops, iteration and

subroutine calls, and these need branching and jumping to work.

  • Sometimes the code needs to jump to another location regardless.

This is called an unconditional jump. For example to avoid the

next line of code being executed at the end of a routine.

  • On the other hand, a jump may be dependent on some condition

being met such as a flag being 1 or 0. This is called a conditional

jump.

  • A relative jump will cause the instruction an offset number away

from the current one to be executed. An absolute jump will go to

the instruction at a specific address.

Data transfer

  • A CPU, in order to process data, needs to move that data around. This includes moving data between its internal registers and it includes moving data in an out of external RAM.

Data transfer

  • The MOV command may include a number of variants within the full instruction set, but it basically copies data from one location to another.
  • The PUSH and POP operations are the commands that control the contents of the stack. The stack is used to control subroutine calls and returning from subroutines.
  • A CPU may have a number of 'ports'. A port is one or more physical pins on the chip assigned to handling data moving into and out of the chip.
  • For example a serial port or an 8 bit data port may be available on the chip. CPUs especially developed for control purposes have many complicated ports, for example an automotive engine management CPU.

Example Notes

  • The first statement .MODEL SMALL is a telling the assembler what kind of memory model to use, in this case 'small' will probably mean only a 16 bit word is needed for addressing purposes. This is faster than having to fully resolve a full 32 bit word address every time.
  • Then the stack is declared along with some symbolic variables.
  • Another declaration .CODE defines the start of the code itself.
  • Labels such as main, mysub and leave are used to identify specific points within the code
  • There are a number of MOV commands to shuffle data around
  • There is a SUB arithmetic command that alters the value of the variable varB
  • There is a conditional jump JZ (JZ :mysub) that is testing the outcome of the prior operation. This code is artificial as VarB was initialised with 35 and then 35 was subtracted, so the result will always be zero. Or this is may be an example of a typical software bug where the programmer did not intend to do that.
  • You can also see an unconditional JMP command (JMP :leave) to by-pass the instruction at mysub.

Further Task

• When you get home see if you can find any

Intel x86 assembly code simulators that

illustrate how all this really works.

• There may be lots of animations on the web

to show this visually.