Assembly Language
COA
PROF. BHUMIKA SINDHAV
Assembly Language
• Assembly language is a low-level programming language - it is closer to machine
code (binary) than high-level programming languages like Python.
• Assembly language uses mnemonics (abbreviations of commands) to signify
instructions; for example, input is written as INP and output is written as OUT.
• Little Man Computer is a representation of assembly language. This simulator will help
you understand assembly language and allow you to check if your instructions are correct.
Assembly Language Mnemonics
INP (Input)
• INP is used to input a number. The number is temporarily stored in the accumulator.
OUT (Output)
• OUT is used to output the number currently stored in the accumulator.
STA (Store)
• STA stores the value that is currently in the accumulator. It can be used to assign a value to a variable.
ADD (Addition)
• ADD is used to add a number to the value currently stored in the accumulator.
SUB (Subtraction)
• SUB takes away a number from the value currently stored in the accumulator.
LDA (Load)
• LDA is used to load the value of a stored variable back into the accumulator.
Assembly Language Mnemonics
BRZ (Branch if Zero)
• BRZ is used to loop only if the value in the accumulator is currently 0.
BRP (Branch if Positive)
• BRP is used to loop only if the value in the accumulator is currently positive (including 0).
BRA (Branch Always)
• BRA is used to loop continuously.
HLT (Halt)
• HLT will stop running the program. Every program MUST have a HLT command.
DAT (Data Definition)
• DAT must be used to define a variable name (and / or set it with a starting value). Data definitions
must be written at the end of the instructions.
Little Man Computer simulator to see how it works. Change the program
https://peterhigginson.co.uk/LMC/?F5=29-Mar-23_07:01:21
ASSEMBLY LEVEL
HIGH-LEVEL LANGUAGE
LANGUAGE
It needs an assembler for It needs a compiler/interpreter for
conversion conversion
In this, we convert an In this, we convert a high-level language
Assembly level language to to Assembly level language to machine
machine level language level language
It is machine dependent It is machine-independent
In these mnemonics, codes
In this English statement is used
are used
It supports low-level
It does not support low-level language
operation
In this, it is easy to access In this, it is difficult to access hardware
hardware component component
In this more compact code No compactness
Machine Language Assembly Language
Machine language is only understood by the Assembly language is only understood
computers. by human beings not by the computers.
In machine language data only represented In assembly language data can be
with the help of binary format (0s and 1s), represented with the help of mnemonics
hexadecimal and octa decimal. such as Mov, Add, Sub, End etc.
Assembly language is easy to understand
Machine language is very difficult to
by the human being as compare to
understand by the human beings.
machine language.
Modifications and error fixing cannot be Modifications and error fixing can be
done in machine language. done in assembly language.
Machine Language Assembly Language
Machine language is very difficult to Easy to memorize the assembly language
memorize so it is not possible to learn the because some alphabets and mnemonics
machine language. are used.
Execution is fast in machine language
Execution is slow as compared to
because all data is already present in binary
machine language.
format.
There is no need of translator. The machine Assembler is used as translator to convert
understandable form is the machine mnemonics into machine understandable
language. form.
Assembly language is the machine
Machine language is hardware dependent.
dependent and it is not portable.
ARM-Cortex Microcontroller Programming
➢ Syntax:
Load a // a obtained the value from the place called a //
ADD12 // 12 is added to the load value a //
Store a // final value is stored in the variable a//
➢ The assembly language programming is developed by the mnemonics such
as ADD, SUB, MUL so on but for ARM programming, some extra instructions
added such as ADCNES and SWINE, etc.
EX: 1. WAP to toggle the single LED through Embedded using ARM cortex
microcontroller.
(Assembly language)
ORG 0000h
MOV r1, #10
MOV r2, #15
ADD r3, r2, r1 // r3=r2+r1 and the final value stored in r3 register//
2.ORG 0000h
MOV r1, #10
MOV r2, #15
SUB r3, r2, r1 // r3=r2-r1 and the final value stored in r3 register//
(C Level Programming)
#include “stm32f10x_gpio.h”
#include “stm32f10x_rcc.h”
GPIO_InitTypeDef GPIO_InitStructure;
int i;
#define LED_PORT GPIOB
Void binky();
Void main()
{
Void binky();
}
void binky(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); //enable the
PORTB pins//
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //set the port frequency//
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //set the PORTB in output//
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All ; //enabled all PORTB pins//
GPIO_Init(GPIOB, &GPIO_InitStructure); //initialize the PORTB pins//
while(1){
GPIO_WriteBit(LED_PORT,GPIO_Pin_8,Bit_SET);
for (i=0;i<1000000;i++);
GPIO_WriteBit(LED_PORT,GPIO_Pin_8,Bit_RESET);
for (i=0;i<1000000;i++);
GPIO_WriteBit(LED_PORT,GPIO_Pin_9,Bit_SET);
for (i=0;i<1000000;i++);
GPIO_WriteBit(LED_PORT,GPIO_Pin_9,Bit_RESET);
for (i=0;i<1000000;i++);
GPIO_WriteBit(LED_PORT,GPIO_Pin_10,Bit_SET);
for (i=0;i<1000000;i++);
GPIO_WriteBit(LED_PORT,GPIO_Pin_10,Bit_RESET);
for (i=0;i<1000000;i++);
}
} Unit-3
(Have to write all assembly lang. program)
Pg no:
7,8
10,11,12,13
18 to 22,28
34
40-43