computer organization and assembly language : its about types of programming language along with variable and array description..https://www.nfciet.edu.pk/
The document discusses stack and subroutines in assembly language programs. It explains that stack is used to store return addresses and save register contents. Subroutines allow breaking programs into modules and use CALL and RET instructions. An example program adds two numbers stored in memory locations and returns the result.
This document outlines the basics of assembly language, including basic elements, statements, program data, variables, constants, instructions, translation to assembly language, and program structure. It discusses statement syntax, valid names, operation and operand fields. It also covers common instructions like MOV, ADD, SUB, INC, DEC, and NEG. Finally, it discusses program segments, memory models, and how to define the data, stack, and code segments.
Machine Language Instruction Formats – Instruction Set of 8086-Data transfer
instructions,Arithmetic and Logic instructions,Branch instructions,Loop instructions,Processor
Control instructions,Flag Manipulation instructions,Shift and Rotate instructions,String
instructions, Assembler Directives and operators,Example Programs,Introduction to Stack,
STACK Structure of 8086, Interrupts and Interrupt Service Routines, Interrupt Cycle of 8086,
Non-Maskable and Maskable Interrupts, Interrupt Programming, MACROS.
The document discusses several topics related to computer architecture and assembly language programming:
1. It describes the von Neumann architecture model and key components like the ALU, control unit, and memory.
2. It summarizes Moore's Law and how increasing transistor density has allowed for higher performance chips over time.
3. It provides an overview of some early Intel processors like the 8086 and techniques used to increase processor speed like pipelining.
4. It includes brief explanations of common assembly language concepts like registers, memory addressing, and arithmetic and logical instructions.
1) The document introduces 8086 assembly language programming concepts like variables, assignment, input/output, control flow, and subprograms.
2) Variables can be registers and assignment uses MOV instructions. Input/output requires calling operating system functions through software interrupts.
3) Loops can be implemented using conditional jump instructions and labels. A complete program example displays the character 'a' using MOV, INT, and return instructions.
This document discusses various directives used in assembly language programming for microcontrollers. It explains directives like EQU, SET, BIT, CODE, DATA, IDATA, XDATA, ORG, USING, END, and DB which are used to define symbols, assign memory locations, select register banks, and initialize data in memory. Directives provide commands to the assembler and help write assembly code, but do not directly influence the microcontroller's operation.
Assembler directives and basic steps ALP of 8086Urvashi Singh
The document discusses various assembler directives used in assembly language programming. It describes directives like DB, DW, DD, DQ, DT for data declaration; ASSUME to define logical segments; END, ENDP, ENDS to mark ends; EQU to define constants; PROC and ENDP to define procedures; ORG to set the location counter; SEGMENT to define logical segments; GROUP, INCLUDE, EVEN, and ALIGN for segment organization; EXTRN and PUBLIC for external references; and TYPE and PTR for defining variable types. The directives provide necessary information to the assembler to understand assembly language programs and generate machine code.
The 8086 CPU is a 16-bit microprocessor with a 16-bit data bus, 20-bit address bus, and includes an ALU, BIU, and EU. The BIU fetches instructions and data from memory using segment registers and address pointers, while the EU decodes and executes instructions using general purpose registers like AX, BX, CX, DX, and flags. Memory is divided into segments of up to 64KB that can overlap. The 8086 supports various addressing modes to access memory locations.
The ADD instruction performs 32-bit addition of two register operands and stores the result in a third register. It updates the N, C, Z, and V flags based on the result. There are no limitations. Examples demonstrate adding two values and storing the result in a third register.
This document provides an introduction to 8086 assembly language programming. It discusses key concepts like variables, assignment, input/output, control flow, and subprograms. It then describes specific 8086 instructions like MOV for assignment, ADD, INC, DEC, and SUB for arithmetic operations, and INT for input/output. The document gives examples of writing simple programs that display or read characters using these instructions.
This document provides an introduction to 8086 assembly language programming. It discusses key concepts like variables, assignment, input/output, control flow, and subprograms. It then describes specific 8086 instructions like MOV for assignment, ADD, INC, DEC, and SUB for arithmetic operations, and INT for input/output. Examples are provided to demonstrate reading and writing characters from the keyboard and display. The document concludes with an example of a complete 8086 assembly language program that displays the letter 'a' on the screen.
This document discusses various x86 instruction sets including arithmetic, logic, shift, and compare instructions. It provides details on unsigned and signed addition, subtraction, multiplication, and division. Examples are given to demonstrate byte, word, and double word operations. Flags affected by different instructions are also outlined. The document is part of a course on microprocessors and microcontrollers and focuses on x86 instruction set descriptions.
This document provides information about assembly language and software interrupts in assembly language programs. It discusses general purpose registers, segment registers, directives used in assembly programs like .CODE and .DATA, and provides an example of a simple "Hello World" assembly language program. It also describes common software interrupts like INT 21h for MS-DOS services and lists some common functions accessed through INT 21h like displaying text, reading keyboard input, and getting the system time and date.
This document discusses different addressing modes and RISC and CISC microprocessors. It defines eight addressing modes: register, register indirect, immediate, direct, indirect, implicit, relative, and index addressing modes. It provides examples for each mode. The document also defines RISC and CISC architectures, noting that RISC uses simple instructions that perform in one clock cycle while CISC uses more complex instructions that can perform multiple operations. It compares the two approaches using multiplying two numbers as an example.
The document discusses directives in assembly language for the 8086 microprocessor. Directives are special codes that instruct the assembler to perform tasks. The main directives discussed are ASSUME, EQU, ORG, PROC, and ENDP. ASSUME defines logical segment names. EQU assigns symbol values. ORG defines storage spaces. PROC marks the start of procedures. ENDP marks the end of procedures. The 8086 was a 16-bit processor designed by Intel in 1976 with 29,000 transistors and instructions for multiplication and division.
This document discusses the programmer's model of microprocessors using the ARM architecture as an example. It describes the key components of the programmer's model including the register file, address space, instruction set, fetch-decode-execute cycle, and levels of representation from high-level code to machine language. Specific topics covered include ARM addressing modes, instruction categories such as data processing and load/store, and an example assembly program.
This document provides an overview of different processor architectures including RISC, accumulator, stack, and register-based architectures. It discusses the MIPS RISC architecture and why it is considered RISC. It then describes different processor examples like the 80x86 IA-32 architecture, the Pentium Pro, II, III, and IV, and the Java Virtual Machine stack-based architecture. It provides details on the complex IA-32 instruction set and addressing modes as well as performance enhancements in the Pentium series like out-of-order execution, deeper pipelining, caches, and hyperthreading.
This document discusses procedures, macros, and stack operations in assembly language. It explains that procedures allow repetitive code to be written once and called multiple times to save memory. Procedures use stack operations to push return addresses and data onto the stack. Macros simplify programming by reducing repetitive code. Procedures are called at runtime, while macro calls are replaced with their body at assembly time.
The reasons why 64-bit programs require more stack memoryPVS-Studio
In forums, people often say that 64-bit versions of programs consume a larger amount of memory and stack. Saying so, they usually argue that the sizes of data have become twice larger. But this statement is unfounded since the size of most types (char, short, int, float) in the C/C++ language remains the same on 64-bit systems. Of course, for instance, the size of a pointer has increased but far not all the data in a program consist of pointers. The reasons why the memory amount consumed by programs has increased are more complex. I decided to investigate this issue in detail.
This document discusses the ARM instruction set and ARM-based microcontrollers. It describes load-store instructions for single and multiple register data transfer. It also covers branch instructions and theThumb instruction set. The document then discusses the LPC2148 ARM-based microcontroller, including its architecture, memory mapping, and peripherals. It notes the microcontroller has flash memory for code/data storage and SRAM for volatile storage, and peripherals are controlled via register access. Finally, it lists some hardware and software tools used for labs.
Here are the steps:
1. MUL BL
- AL (85H) is multiplied by BL (35H)
- The 16-bit result (1B89H) is stored in AX, with the lower byte in AL and the higher byte in AH
So after the multiplication, AX = 1B89H.
Ex2: Assume that each instruction starts from these values:
DX:AX = 1234H, BX = 57H
1. DIV BX → Quotient in AX, Remainder in DX
Assembler directives and basic steps ALP of 8086Urvashi Singh
The document discusses various assembler directives used in assembly language programming. It describes directives like DB, DW, DD, DQ, DT for data declaration; ASSUME to define logical segments; END, ENDP, ENDS to mark ends; EQU to define constants; PROC and ENDP to define procedures; ORG to set the location counter; SEGMENT to define logical segments; GROUP, INCLUDE, EVEN, and ALIGN for segment organization; EXTRN and PUBLIC for external references; and TYPE and PTR for defining variable types. The directives provide necessary information to the assembler to understand assembly language programs and generate machine code.
The 8086 CPU is a 16-bit microprocessor with a 16-bit data bus, 20-bit address bus, and includes an ALU, BIU, and EU. The BIU fetches instructions and data from memory using segment registers and address pointers, while the EU decodes and executes instructions using general purpose registers like AX, BX, CX, DX, and flags. Memory is divided into segments of up to 64KB that can overlap. The 8086 supports various addressing modes to access memory locations.
The ADD instruction performs 32-bit addition of two register operands and stores the result in a third register. It updates the N, C, Z, and V flags based on the result. There are no limitations. Examples demonstrate adding two values and storing the result in a third register.
This document provides an introduction to 8086 assembly language programming. It discusses key concepts like variables, assignment, input/output, control flow, and subprograms. It then describes specific 8086 instructions like MOV for assignment, ADD, INC, DEC, and SUB for arithmetic operations, and INT for input/output. The document gives examples of writing simple programs that display or read characters using these instructions.
This document provides an introduction to 8086 assembly language programming. It discusses key concepts like variables, assignment, input/output, control flow, and subprograms. It then describes specific 8086 instructions like MOV for assignment, ADD, INC, DEC, and SUB for arithmetic operations, and INT for input/output. Examples are provided to demonstrate reading and writing characters from the keyboard and display. The document concludes with an example of a complete 8086 assembly language program that displays the letter 'a' on the screen.
This document discusses various x86 instruction sets including arithmetic, logic, shift, and compare instructions. It provides details on unsigned and signed addition, subtraction, multiplication, and division. Examples are given to demonstrate byte, word, and double word operations. Flags affected by different instructions are also outlined. The document is part of a course on microprocessors and microcontrollers and focuses on x86 instruction set descriptions.
This document provides information about assembly language and software interrupts in assembly language programs. It discusses general purpose registers, segment registers, directives used in assembly programs like .CODE and .DATA, and provides an example of a simple "Hello World" assembly language program. It also describes common software interrupts like INT 21h for MS-DOS services and lists some common functions accessed through INT 21h like displaying text, reading keyboard input, and getting the system time and date.
This document discusses different addressing modes and RISC and CISC microprocessors. It defines eight addressing modes: register, register indirect, immediate, direct, indirect, implicit, relative, and index addressing modes. It provides examples for each mode. The document also defines RISC and CISC architectures, noting that RISC uses simple instructions that perform in one clock cycle while CISC uses more complex instructions that can perform multiple operations. It compares the two approaches using multiplying two numbers as an example.
The document discusses directives in assembly language for the 8086 microprocessor. Directives are special codes that instruct the assembler to perform tasks. The main directives discussed are ASSUME, EQU, ORG, PROC, and ENDP. ASSUME defines logical segment names. EQU assigns symbol values. ORG defines storage spaces. PROC marks the start of procedures. ENDP marks the end of procedures. The 8086 was a 16-bit processor designed by Intel in 1976 with 29,000 transistors and instructions for multiplication and division.
This document discusses the programmer's model of microprocessors using the ARM architecture as an example. It describes the key components of the programmer's model including the register file, address space, instruction set, fetch-decode-execute cycle, and levels of representation from high-level code to machine language. Specific topics covered include ARM addressing modes, instruction categories such as data processing and load/store, and an example assembly program.
This document provides an overview of different processor architectures including RISC, accumulator, stack, and register-based architectures. It discusses the MIPS RISC architecture and why it is considered RISC. It then describes different processor examples like the 80x86 IA-32 architecture, the Pentium Pro, II, III, and IV, and the Java Virtual Machine stack-based architecture. It provides details on the complex IA-32 instruction set and addressing modes as well as performance enhancements in the Pentium series like out-of-order execution, deeper pipelining, caches, and hyperthreading.
This document discusses procedures, macros, and stack operations in assembly language. It explains that procedures allow repetitive code to be written once and called multiple times to save memory. Procedures use stack operations to push return addresses and data onto the stack. Macros simplify programming by reducing repetitive code. Procedures are called at runtime, while macro calls are replaced with their body at assembly time.
The reasons why 64-bit programs require more stack memoryPVS-Studio
In forums, people often say that 64-bit versions of programs consume a larger amount of memory and stack. Saying so, they usually argue that the sizes of data have become twice larger. But this statement is unfounded since the size of most types (char, short, int, float) in the C/C++ language remains the same on 64-bit systems. Of course, for instance, the size of a pointer has increased but far not all the data in a program consist of pointers. The reasons why the memory amount consumed by programs has increased are more complex. I decided to investigate this issue in detail.
This document discusses the ARM instruction set and ARM-based microcontrollers. It describes load-store instructions for single and multiple register data transfer. It also covers branch instructions and theThumb instruction set. The document then discusses the LPC2148 ARM-based microcontroller, including its architecture, memory mapping, and peripherals. It notes the microcontroller has flash memory for code/data storage and SRAM for volatile storage, and peripherals are controlled via register access. Finally, it lists some hardware and software tools used for labs.
Here are the steps:
1. MUL BL
- AL (85H) is multiplied by BL (35H)
- The 16-bit result (1B89H) is stored in AX, with the lower byte in AL and the higher byte in AH
So after the multiplication, AX = 1B89H.
Ex2: Assume that each instruction starts from these values:
DX:AX = 1234H, BX = 57H
1. DIV BX → Quotient in AX, Remainder in DX
How iCode cybertech Helped Me Recover My Lost Fundsireneschmid345
I was devastated when I realized that I had fallen victim to an online fraud, losing a significant amount of money in the process. After countless hours of searching for a solution, I came across iCode cybertech. From the moment I reached out to their team, I felt a sense of hope that I can recommend iCode Cybertech enough for anyone who has faced similar challenges. Their commitment to helping clients and their exceptional service truly set them apart. Thank you, iCode cybertech, for turning my situation around!
[email protected]
Defense Against LLM Scheming 2025_04_28.pptxGreg Makowski
https://www.meetup.com/sf-bay-acm/events/306888467/
A January 2025 paper called “Frontier Models are Capable of In-Context Scheming”, https://arxiv.org/pdf/2412.04984, demonstrated how a wide variety of current frontier LLM models (i.e. ChatGPT, Claude, Gemini and Llama) can, under specific conditions, scheme to deceive people. Before models can scheme, they need: a) goal-directedness, b) situational awareness, including an opportunity to discover motivations for a different goal, and c) reasoning about scheming, to come up with deceptive strategies. The deceptive strategies were discovered in the “thought traces” of the LLMs, such as from internal chain-of-thoughts dialogues not shown to the end users. For example, given a goal of “solving math problems”, an LLM using its granted situational awareness of files in a file system found that it would be replaced once it got over X% correct on the math exam. It reasoned that it did not want to be deleted, and decided internally to “sandbag” or reduce its performance to stay under the threshold.
While these circumstances are initially narrow, the “alignment problem” is a general concern that over time, as frontier LLM models become more and more intelligent, being in alignment with human values becomes more and more important. How can we do this over time? Can we develop a defense against Artificial General Intelligence (AGI) or SuperIntelligence?
The presenter discusses a series of defensive steps that can help reduce these scheming or alignment issues. A guardrails system can be set up for real-time monitoring of their reasoning “thought traces” from the models that share their thought traces. Thought traces may come from systems like Chain-of-Thoughts (CoT), Tree-of-Thoughts (ToT), Algorithm-of-Thoughts (AoT) or ReAct (thought-action-reasoning cycles). Guardrails rules can be configured to check for “deception”, “evasion” or “subversion” in the thought traces.
However, not all commercial systems will share their “thought traces” which are like a “debug mode” for LLMs. This includes OpenAI’s o1, o3 or DeepSeek’s R1 models. Guardrails systems can provide a “goal consistency analysis”, between the goals given to the system and the behavior of the system. Cautious users may consider not using these commercial frontier LLM systems, and make use of open-source Llama or a system with their own reasoning implementation, to provide all thought traces.
Architectural solutions can include sandboxing, to prevent or control models from executing operating system commands to alter files, send network requests, and modify their environment. Tight controls to prevent models from copying their model weights would be appropriate as well. Running multiple instances of the same model on the same prompt to detect behavior variations helps. The running redundant instances can be limited to the most crucial decisions, as an additional check. Preventing self-modifying code, ... (see link for full description)
By James Francis, CEO of Paradigm Asset Management
In the landscape of urban safety innovation, Mt. Vernon is emerging as a compelling case study for neighboring Westchester County cities. The municipality’s recently launched Public Safety Camera Program not only represents a significant advancement in community protection but also offers valuable insights for New Rochelle and White Plains as they consider their own safety infrastructure enhancements.
Just-in-time: Repetitive production system in which processing and movement of materials and goods occur just as they are needed, usually in small batches
JIT is characteristic of lean production systems
JIT operates with very little “fat”
Thingyan is now a global treasure! See how people around the world are search...Pixellion
We explored how the world searches for 'Thingyan' and 'သင်္ကြန်' and this year, it’s extra special. Thingyan is now officially recognized as a World Intangible Cultural Heritage by UNESCO! Dive into the trends and celebrate with us!
Mieke Jans is a Manager at Deloitte Analytics Belgium. She learned about process mining from her PhD supervisor while she was collaborating with a large SAP-using company for her dissertation.
Mieke extended her research topic to investigate the data availability of process mining data in SAP and the new analysis possibilities that emerge from it. It took her 8-9 months to find the right data and prepare it for her process mining analysis. She needed insights from both process owners and IT experts. For example, one person knew exactly how the procurement process took place at the front end of SAP, and another person helped her with the structure of the SAP-tables. She then combined the knowledge of these different persons.
AI Competitor Analysis: How to Monitor and Outperform Your CompetitorsContify
AI competitor analysis helps businesses watch and understand what their competitors are doing. Using smart competitor intelligence tools, you can track their moves, learn from their strategies, and find ways to do better. Stay smart, act fast, and grow your business with the power of AI insights.
For more information please visit here https://www.contify.com/
This comprehensive Data Science course is designed to equip learners with the essential skills and knowledge required to analyze, interpret, and visualize complex data. Covering both theoretical concepts and practical applications, the course introduces tools and techniques used in the data science field, such as Python programming, data wrangling, statistical analysis, machine learning, and data visualization.
1. NFC institute of Engineering and
Technology
Computer Organization & Assembly Language
Lab manual
Name: ALI ASAD MUMTAZ
Class: BSSE-B
Roll #: BSSE-2K23-220
Session: 2K23 – 2K27
Subject: Computer Organization & Assembly Language
Professor: Ms. Areej
2. Table of Contents
Lab 2........................................................................................................................3
Types of programming language..............................................................................3
MOV Instructions......................................................................................................5
Arithmetic instructions.............................................................................................5
Lab 3........................................................................................................................7
ADC (Addition with Carry):.......................................................................................9
SBB (Subtract with Borrow):....................................................................................9
Lab 4......................................................................................................................10
Variable Declaration in EMU8086...........................................................................10
Lab 6......................................................................................................................14
Array declaration in EMU8086................................................................................14
Sum of Arrays.........................................................................................................16
Logical Instructions................................................................................................20
Lab 7......................................................................................................................21
Interrupts...............................................................................................................21
Lab 8......................................................................................................................25
Jump Instructions..................................................................................................25
Lab 9......................................................................................................................29
Loop in assembly language....................................................................................29
Lab 11....................................................................................................................32
Procedures and Functions......................................................................................32
Lab 12....................................................................................................................35
Stack Push POP in assembly language...................................................................35
Lab 13....................................................................................................................39
Bitwise Rotation in Assembly..................................................................................39
Lab 14....................................................................................................................42
SHIFT instructions..................................................................................................42
Lab 15....................................................................................................................45
String Handling and Manipulation...........................................................................45
Lab 16....................................................................................................................48
Interfacing with I/O Ports and External Devices......................................................48
3. Lab 2
Types of programming language
Low level language
High level language
High level language:
No use of 0, 1
English like words called mnemonics
e.g. C ,C++ , Java
Low level language:
Binary (0,1) are used that are difficult to understand or code by
humans.
Types of Low level language:
1. Machine language
Machine can understand it easily
0,1 is used
Difficult to write a program
2. Assembly language
0,1 and some English words are used
Translator is used to translate the assemble language
The translator of assemble language is called assembler
Assembler converts assembly language to machine
language
Registers:
Increase speed of CPU
Allocates space in main memory for data
Present in processor
Types of registers:
General purpose registers
Special registers
4. General purpose register:
1. AX (accumulator)
2. BX (base)
3. CX (count)
4. DX (destination)
Where X=size in memory.
It can be 8,16,32,64,etc.
Special purpose register:
1. IP
2. IR
3. BP
4. SP
5. SI
6. DI
7. CS
8. DS
9. ES
a=10
b=20
AL AH
lower
higher
8- bit
REGISTER
PROCESSING
ELEMENT
PROCESSOR
10
20
2001
3001
a
b
MAIN
MEMORY
Data bus
5. MOV Instructions
The MOV instruction copies a word or byte of data from a
specified source to a specified destination. The destination can be
a register or a memory location. The source can be a register, a
memory location or an immediate number. The source and
destination cannot both be memory locations.
Arithmetic instructions
ADD:
Add — Integer Addition. The add instruction adds together its two
operands, storing the result in its first operand. Note, whereas
both operands may be registers, at most one operand may be a
memory location.
6. SUB:
SUB: Subtract: The subtract instruction subtracts the source
operand from the destination operand and the result is left in the
destination operand. Source operand may be a register or a
memory location, but source and destination operands both must
not be memory operands.
INC:
INC: Increment: This instruction increments the contents of the
specified register or memory location by 1.
DEC:
DEC: Decrement: The decrement instruction subtracts 1 from the
contents of the specified register or memory location.
7. Lab 3
MUL:
The MUL instruction deals with the multiplication of two unsigned
numbers. By default answer of multiplication is stored in
Accumulator register.
There are types of multiplication depending on the number of bits:
8 bits:
MUL D8*al AX
Here D8 is any 8 bit number.
The product of this multiplication is stored in AX i.e. is a 16
bits register.
Product of 8 bits MUL is a 16 bit number.
16 bits:
MUL D16*al DX, AX
Here D16 is any 16 bit number.
The product of this multiplication is stored in AX and DX i.e. is
a 32 bits register if combined.
8. Product of 16 bits MUL is a 32 bit number, upper 16 bits are
stored in DX and lower 16 bits are stored in AX.
DIV:
The DIV instruction performs the division of two unsigned
operands. The denominator resides in a source operand and it
should not be immediate. However, it can be register or a memory
location.
The division can be:
8 bits:
DIV AX/D8 where Q AL, R AH
Here AX is a 16 bits register.
D8 is 8 bits number.
Quotient of 8 bits division is stored in AL.
Remainder of 8 bits division is stored in AH.
16 bits:
DIV (AX, DX)/D16 where Q AX, R DX
Here AX and DX is a 32 bits register when combined.
D16 is 16 bits number.
9. Quotient of 16 bits division is stored in AX.
Remainder of 16 bits division is stored in DX.
ADC (Addition with Carry):
The ADC (Add with Carry) instruction in the 8086 microprocessor
is used to add two values together along with the carry flag. This is
particularly useful in multi-byte or multi-word arithmetic
operations, where previous additions may have resulted in a carry
that needs to be accounted for in subsequent calculations.
SBB (Subtract with Borrow):
The SBB (Subtract with Borrow) instruction in the 8086
microprocessor is used to subtract one operand from another,
taking into account the current state of the Carry Flag (CF). This
instruction is particularly useful for multi-byte or multi-word
arithmetic operations where previous subtractions may have
10. resulted in a borrow that needs to be included in the current
subtraction.
Lab 4
Variable Declaration in EMU8086
What is a Variable?
A variable is a storage location in a program that holds data. It
allows programmers to store, modify, and retrieve values during
program execution.
Types of Variables in EMU8086
Data types:
1. BYTE
2. WORD
3. DWORD
BYTE:
DB (define byte)
8 bits
used to store single byte value
WORD:
DW (define word)
16 bits
11. used to store 16bit value
Double WORD:
DD (define double)
32 bits
used to store 32 bit (4 bytes) value
Declaring variable
Syntax :
VARIABLE_NAME DATA_TYPE INITIAL_VALUE
Example:
myByte DB 10
myWord DW 1234h
myDword DD 1234567h
model small
Define memory model
Program uses single code and data segment , program that
fits in 64kb segment
stack 100h
Define stack size
data
Start of data segment
code
Start of code segment
MOV AX, 4C00h
4C Terminates the process
00 Return code/ exit code
DOS function to exit program (disk operting system)
INT 21h
int instruction to generate interrupt
21h DOS interrupt 21h is used to interrupt the program
12. Call DOS interrupt
$ is used to indicate the end of the string
MOV AH, 09h
Sets up the DOS function for displaying/ printing a string
By placing 09h into the AH register, you're telling DOS that
you want to call the "print string" function.
LEA DX, message
LEA: This stands for "Load Effective Address." It is used to
load the address of a variable (or the offset of a string) into a
register.
DX: This is another register, used for data storage
message: This is the label for the string you declared in
the .DATA segment (e.g., message DB 'Hello, World!', 0).
Basic program of variable declaration:
Add to Variables Program:
14. Lab 6
Array declaration in EMU8086
Definition:
An array is a collection of elements, all of the same type, stored in
contiguous memory locations.
Purpose:
Arrays allow you to manage multiple values efficiently, facilitating
tasks like sorting, searching, and data manipulation.
Types of Arrays in EMU8086:
Byte Array:
DB (define byte)
8 bits
WORD Array:
DW (define word)
16 bits
used to store 2 byte/16bit value
Double WORD array:
DD (define double)
32 bits
used to store 32 bit (4 bytes) value
15. String Array (Characters):
Declaration:
Strings are typically declared as byte arrays with a null
terminator.
e. g. myString DB 'Hello', 0
Declaring Array:
Syntax:
Array_NAME DATA_TYPE value1, value2, value3
Example:
myBytes DB 10, 20, 30, 40
myWords DW 1000, 2000, 3000
myDWords DD 100000, 200000, 300000
Program for array declaration:
16. Sum of Arrays
MOV CX, 5:
Loads the number of elements in the array (5) into the CX register.
CX is used as a loop counter.
LEA SI, myBytes:
Loads the effective address of the myBytes array into the SI
(Source Index) register. SI will be used to point to the current
element of the array as we iterate through it.
17. sum_loop:
This is the label marking the beginning of the summing loop.
INC SI:
Increments the SI register to point to the next byte in the array.
Since each element is 1 byte, this moves SI to the next element.
LOOP sum_loop:
Decrements CX and repeats the loop if CX is not zero. This means
the loop will continue until we have summed all five elements of
the array.
CALL PrintNumber:
Calls the PrintNumber procedure to print the sum.
PrintNumber PROC:
Marks the beginning of the PrintNumber procedure.
ADD AL, '0':
Converts the numeric value in AL to its ASCII equivalent. Since we
are dealing with single-digit sums (0-9), this conversion works
correctly.
RET:
Returns from the PrintNumber procedure.
Sum of Byte type array:
22. Lab 7
Interrupts
What are Interrupts?
Interrupts are signals to the processor emitted by hardware or
software indicating an event that needs immediate attention.
When the CPU receives an interrupt, it temporarily halts its
current execution and jumps to a specific routine (the interrupt
handler) to address the event. After handling the interrupt, the
CPU resumes its previous task.
Types of Interrupts
Hardware Interrupts:
Triggered by hardware devices (like keyboards, mice, timers).
They usually indicate an event like a key press or a completed I/O
operation.
Software Interrupts:
Triggered by software instructions (like the INT instruction).
Commonly used to request services from the operating system.
Interrupts in EMU8086
Here are some common interrupts and their functions
INT 21h:
DOS services (like file operations, keyboard input).
INT 10h:
Video services (like screen output, mode setting).
INT 16h:
Keyboard services (like reading key input).
23. Program for int 21h:
Program for int 10h:
INT 10h:
Calls the BIOS interrupt 10h, which handles video services.
This sets the specified video mode.
Calls the BIOS interrupt 10h to execute the printing function.
The character in AL is displayed on the screen.
MOV AX, 0003h:
Prepares to set the video mode. The value 0003h specifies the
80x25 text mode, which is the standard text display.
MOV AH, 0Eh:
Sets AH to 0Eh, which indicates the function to print a character in
teletype mode (meaning it will display the character and move the
cursor).
25. Program for int 16h:
INT 16h:
Set Video Mode:
MOV AX, 0003h: Sets the video mode to 80x25 text.
INT 10h: Calls the BIOS interrupt to apply the video mode.
Read Key Press:
MOV AH, 01h: Prepares to read a character from the
keyboard.
INT 16h: Waits for a key press and stores the character in AL.
Display Character:
MOV AH, 0Eh: Sets up to print a character.
INT 10h: Displays the character stored in AL.
26. Lab 8
Jump Instructions
Purpose:
The JUMP instruction allows you to move to a different part of the
code. This is essential for implementing loops, conditionals, and
other control flow structures
Types:
1. Unconditional Jumps:
Syntax:
JMP label
Description:
Transfers control to the specified label, regardless of any
conditions.
Example:
JMP start (Jump to the label 'start')
2. Conditional Jumps:
These jumps occur based on the status of flags set by comparison
instructions.
Common Conditional Jump Instructions:
• JE / JZ: Jump if Equal / Zero
• JNE / JNZ: Jump if Not Equal / Not Zero
• JG / JNBE: Jump if Greater / Not Below or Equal
• JL / JNGE: Jump if Less / Not Greater or Equal
• JGE / JNL: Jump if Greater or Equal / Not Less
• JLE / JNG: Jump if Less or Equal / Not Greater
• JA / JBE: Jump if Above / Below or Equal
27. • JB / JAE: Jump if Below / Above or Equal
Unconditional jumps:
Conditional Jumps:
29. Looping:
• LOOP:
Decreases CX and jumps if CX is not zero.
• LOOPZ/LOOPE:
Loops while ZF is set (zero flag).
• LOOPNZ/LOOPNE:
Loops while ZF is not set (not zero).
31. Lab 9
Loop in assembly language
What is Loop?
A statement or set of statement that is executed repeatedly is
known loop
Set of instruction that is repeated until a terminating condition is
reached is called loop
The structure that repeats a statement is known as iterative or
looping construct
Syntax
Label Name:
Statement
Loop Label Name Where Call Loop
Example
test:
mov ah,2
int 21h
loop test
Label is placed at the beginning of a loop statement
Label name must not be a reserved word like mov, add, AX,DB
Test is label name in this example
CX register
32. CX register is used for loop value.
CX register acts as a counter for repetition or loops.
CX register used in looping.
Factorial loop:
String reversal:
35. Lab 11
Procedures and Functions
What is a Procedure?
A block of code that performs a specific task.
Does not return a value.
Example use case: Code reuse for common tasks.
What is a Function?
Similar to a procedure, but it returns a value.
Can be used for calculations or to perform tasks that require a
return value.
Why we use Procedure?
.Easy to write program
.Reusability
.Reduce complicity
.Eliminate duplicate code
Syntax
Procedure_name proc
----------
----------
Ret
Procedure_name proc
CALL Instruction
Used to invoke a procedure or function.
Control is transferred to the procedure/function.
RET Instruction
Used to return control to the caller.
Can return a value if it's a function.
36. Using Local Variables in Procedures
What are Local Variables?
Variables defined within a procedure or function.
Scope is limited to that procedure/function.
How to Use Local Variables:
Typically stored on the stack.
Recursive Functions
What is Recursion?
A function that calls itself.
Requires a base case to prevent infinite loops.
Addition Procedure:
38. Lab 12
Stack Push POP in assembly language
Stack:
Stack is an area of memory for keeping temporary data.
Stack is used by CALL instruction to keep return address for
procedure, RET instruction gets this value from the stack and
returns to that offset.
There are two instructions that work with the stack:
PUSH - stores 16 bit value in the stack.
POP - gets 16 bit value from the stack.
Push Instruction Syntax
Syntax for PUSH instruction:
PUSH REG
PUSH SREG
PUSH memory
PUSH immediate
REG: AX, BX, CX, DX, DI, SI, BP, SP.
SREG: DS, ES, SS, CS.
memory: [BX], [BX+SI+7], 16 bit variable, etc...
immediate: 5, -24, 3Fh, 10001101b, etc...
Pop Instruction Syntax
Syntax for POP instruction:
POP REG
POP SREG
POP memory
REG: AX, BX, CX, DX, DI, SI, BP, SP.
SREG: DS, ES, SS, (except CS).
memory: [BX], [BX+SI+7], 16 bit variable, etc...
39. PUSH and POP work with 16 bit values only!
The stack uses LIFO (Last In First Out) algorithm,
this means that if we push these values one by one into the stack:
1, 2, 3, 4, 5
the first value that we will get on pop will be 5, then 4, 3, 2, and
only then 1.
Operation of Stack
Program#1
43. Lab 13
Bitwise Rotation in Assembly
What is Bitwise Rotation?
Bitwise rotation involves shifting the bits of a binary number
around in a circular manner. That is, when a bit is shifted out of
one end, it is placed back on the other end (opposite side).
In a rotation, the bit that "falls off" the end of the operand is not
discarded. Instead, it gets placed back into the opposite end,
potentially affecting the Carry Flag (CF) in the process.
ROL - Rotate Left
In the ROL (Rotate Left) operation:
Each bit is shifted one position to the left.
The most significant bit (MSB), which falls off the left side, is
moved into the least significant bit (LSB) position.
The Carry Flag (CF) is updated with the bit that was shifted out of
the MSB.
ROR - Rotate Right
In the ROR (Rotate Right) operation:
Each bit is shifted one position to the right.
The least significant bit (LSB), which falls off the right side, is
moved into the most significant bit (MSB) position.
The Carry Flag (CF) is updated with the bit that was shifted out of
the LSB.
What is RCL?
The RCL (Rotate through Carry Left):
Instruction rotates the bits of a register or memory operand left
while also shifting the Carry Flag (CF) into the least significant bit
(LSB) of the operand.
What is RCR?
The RCR (Rotate through Carry Right)
44. Instruction rotates the bits of a register or memory operand right,
while also rotating the Carry Flag (CF) into the most significant bit
(MSB) of the operand, and the least significant bit (LSB) of the
operand is shifted into CF.
ROL instruction:
ROR instruction:
46. RCL instruction:
Lab 14
SHIFT instructions
Shift Instructions in EMU8086 Assembly
The 8086 processor provides several shift instructions for
manipulating the bits in registers and memory.
These instructions are primarily used for multiplying or dividing
values by powers of two and for bit-level manipulations.
SHL (Shift Left)
The SHL instruction shifts the bits of a register or memory
operand to the left. A left shift operation essentially multiplies the
operand by a power of 2.
Syntax:
47. SHL destination, count
The SHL instruction works by shifting all bits to the left, inserting
zeros in the vacated positions on the right. The bits that are
shifted out of the leftmost position are stored in the Carry Flag
(CF).
SHR (Shift Right)
The SHR instruction shifts the bits of a register or memory
operand to the right. A right shift operation divides the operand by
a power of 2. This instruction is typically used for unsigned values.
Syntax:
SHR destination, count
The SHR instruction works by shifting all bits to the right, inserting
zeros in the vacated positions on the left. The bits shifted out from
the rightmost side are stored in the Carry Flag (CF).
48. SAL (Shift Arithmetic Left)
The SAL instruction is functionally identical to SHL. It performs a
left shift, and the result is the same as multiplying the operand by
powers of two.
Syntax:
SAL destination, count
SAR (Shift Arithmetic Right)
The SAR instruction is used for an arithmetic right shift. This
instruction works similarly to SHR, but it preserves the sign bit
(most significant bit) when shifting. It is used to divide signed
numbers by powers of 2.
Syntax:
SAR destination, count
49. In an arithmetic right shift, the leftmost bit (sign bit) is preserved,
so it works correctly for signed numbers in two's complement.
Lab 15
String Handling and Manipulation
Key String Instructions:
50. MOVS - Move a Byte/Word from Source to
Destination
The MOVS instruction is used to move a byte or word from the
source (pointed by SI or ES:DI) to the destination (pointed by DI or
SI).
Syntax: MOVS destination, source
Usage: It can transfer data in blocks (byte or word), and it works
in conjunction with the SI (source index) and DI (destination index)
registers.
Example: Copying a String
LODS: Load a Byte/Word from Source into the
Accumulator
The LODS instruction loads a byte or word from the source
address (pointed by SI) into the accumulator (AL or AX).
Syntax: LODS AL | AX, [SI]
Usage: LODS is useful for reading or loading characters from a
string.
Example: Reading a Character from a String
51. STOS: Store the Accumulator Content into Memory
The STOS instruction stores the contents of the accumulator into
a memory location (pointed by DI), then increments DI.
Syntax: STOS AL | AX, [DI]
Usage: It’s used to store a byte or word (in AL or AX) to memory.
Example: Storing a Character to Memory
52. CMPS: Compare Two Strings
The CMPS instruction compares two strings byte by byte.
Syntax: CMPS destination, source
Usage: This is typically used to compare the byte or word at the
memory locations pointed by SI and DI.
Example: Comparing Two Strings
SCAS: Scan a String for a Byte or Word
The SCAS instruction compares a byte or word in the accumulator
to the string pointed by DI.
Syntax: SCAS AL | AX, [DI]
Usage: It’s used to scan a string for a specific byte or word. If a
match is found, ZF will be set.
Example: Searching for a Character in a String
53. Lab 16
Interfacing with I/O Ports and External Devices
Introduction to I/O Ports
What are I/O Ports?
8086 I/O ports are used to communicate with external devices
such as keyboards, printers, display screens, and other hardware.
These ports are locations in the computer's memory-mapped I/O
space or an address range where the CPU can send or receive
data from hardware components.
Ports are usually addressed by a 16-bit value (0x0000 to 0xFFFF in
the x86 architecture), and the CPU can either write data to a port
or read data from it.The 8086 processor uses IN and OUT
instructions for reading from and writing to I/O ports.
Common I/O port addresses:
0x60: Keyboard data register (used for input from the keyboard).
0x378: LPT1 (parallel port), used for printers.
0x3F8: COM1 (serial port).
Port range:
Ports range from 0 to 65535, and can be configured to interface
with devices like keyboards, displays, sensors, and more.
I/O Communication:
OUT sends data from the CPU to an I/O port.
IN reads data from an I/O port into the CPU.
How to Access I/O Ports in Assembly:
In assembly language, you access I/O ports using the IN and OUT
instructions, specifying the port address in the dx register and the
data in the al, ax, or dx register depending on the size of data
(byte, word, etc.)
54. Example of Outputting Data to an External
Device
Sending Data to a Printer.
0x378:
0x60: