Assembly Language Programming

Assembly programming moves data between registers and memory (MOV), performs arithmetic that updates flags, and controls flow with loops and conditional jumps; CX is the built-in loop counter.

Key formulas & points

Skim these first — then read the full notes below.

  • Directives: DB, DW, END, SEGMENT, ASSUME
  • Procedures CALL/RET; stack for parameters and return address
  • String ops MOVS, CMPS with REP prefix

Topic details

Introduction

Instructions operate on registers and memory with addressing modes (immediate, register, direct, register-indirect, based-indexed). Data-transfer (MOV, PUSH, POP), arithmetic (ADD, SUB, MUL, DIV) and control (JMP, Jcc, LOOP, CALL) form the core instruction set.

Scope in B.Tech and GATE syllabus

The LOOP instruction decrements CX and jumps while CX ≠ 0, making counted loops compact. Conditional jumps test flags set by the previous arithmetic/compare.

Key relations & formulas

Formulas (Indian textbook notation)

  • MOVdest,srcregistermemorytransfersMOV dest, src - \frac{register}{memory} transfers

Formulas (Indian textbook notation)

  • ADDSUBwithflagupdates;MULIMULformultiply\frac{ADD}{SUB} with flag updates; \frac{MUL}{IMUL} for multiply

Formulas (Indian textbook notation)

  • LOOPusesCXascounter;DECCX;JNZlabelLOOP uses CX as counter; DEC CX; JNZ label

Notation and sign conventions

Relation 1 —
MOVdest,srcregistermemorytransfersMOV dest, src - \frac{register}{memory} transfers

Formulas (Indian textbook notation)

  • MOVdest,srcregistermemorytransfersMOV dest, src - \frac{register}{memory} transfers
Write this relation with symbols exactly as in Microprocessor Architecture & Programming — Ramesh Gaonkar before substituting numbers. Examiners award partial marks for a correct setup even when arithmetic slips.
Relation 2 —
ADDSUBwithflagupdates;MULIMULformultiply\frac{ADD}{SUB} with flag updates; \frac{MUL}{IMUL} for multiply

Formulas (Indian textbook notation)

  • ADDSUBwithflagupdates;MULIMULformultiply\frac{ADD}{SUB} with flag updates; \frac{MUL}{IMUL} for multiply
Write this relation with symbols exactly as in Microprocessor Architecture & Programming — Ramesh Gaonkar before substituting numbers. Examiners award partial marks for a correct setup even when arithmetic slips.
Relation 3 —
LOOPusesCXascounter;DECCX;JNZlabelLOOP uses CX as counter; DEC CX; JNZ label

Formulas (Indian textbook notation)

  • LOOPusesCXascounter;DECCX;JNZlabelLOOP uses CX as counter; DEC CX; JNZ label
Write this relation with symbols exactly as in Microprocessor Architecture & Programming — Ramesh Gaonkar before substituting numbers. Examiners award partial marks for a correct setup even when arithmetic slips.

Fundamentals and definitions

The stack (in the stack segment, indexed by SP) holds return addresses for CALL/RET and saved registers via PUSH/POP; each PUSH decrements SP by 2, each POP increments it by 2.

Governing relations in practice

String instructions (MOVS, CMPS, SCAS) process arrays automatically incrementing SI/DI, and the REP prefix repeats them CX times — efficient block moves and searches.

Design and analysis considerations

Assembler directives (DB, DW define bytes/words; SEGMENT, ASSUME, END structure the program) are processed at assembly time, not run time; distinguishing them from executable instructions is a common exam point.

Assumptions and validity limits

State assumptions explicitly before using any relation for assembly language programming — steady state, uniform properties, linear elastic material, ideal gas, incompressible flow, etc., as applicable.
Wrong assumptions invalidate the entire solution even when the formula is correct. In Microprocessors viva and GATE descriptive questions, listing valid assumptions often earns separate marks.

Step-by-step problem approach

1. Read the question and list given data with SI units (common in Microprocessors papers).
2. Draw a neat labelled diagram where applicable — examiners in Indian universities award diagram marks even when arithmetic slips.
3. Identify which relation from this topic applies to assembly language programming.
4. Use equation 1:
MOVdest,srcregistermemorytransfersMOV dest, src - \frac{register}{memory} transfers
.
5. Use equation 2:
ADDSUBwithflagupdates;MULIMULformultiply\frac{ADD}{SUB} with flag updates; \frac{MUL}{IMUL} for multiply
.
6. Substitute values, compute, and verify units and sign (direction).
7. State conclusion in one line — e.g. safe/unsafe, stable/unstable, feasible/infeasible.

Applications & exam relevance

Assembly Language Programming appears in embedded and industrial controllers. In Indian electrical curricula this topic is tested because it connects theory to 8086 architecture and interfacing.
GATE and semester exams often combine assembly language programming with earlier units — revise prerequisites before attempting mixed problems.
Industry interview panels sometimes ask: "Where did you use assembly language programming?" — answer with a lab, mini-project, or plant visit example if possible.

Common mistakes in exams

• Forgetting MUL/DIV use implicit AX (and DX) rather than an arbitrary register
• Miscounting SP changes across PUSH/POP (2 bytes each in 8086)
• Using LOOP without initialising CX
• Confusing assembler directives with executable instructions

Quick revision checklist

Before attempting assembly language programming problems, confirm you can:
1. Directives: DB, DW, END, SEGMENT, ASSUME
2. Procedures CALL/RET; stack for parameters and return address
3. String ops MOVS, CMPS with REP prefix
Revise the solved examples in Microprocessor Architecture & Programming — Ramesh Gaonkar and one previous-year GATE or university paper for this unit.

Worked examples

Try the problem first — open the solution when you are ready to check.

Stack pointer after PUSH operations

Problem

SP = 2000H initially. Trace SP after PUSH AX, PUSH BX, then one POP in an 8086.

Solution

Each PUSH decrements SP by 2.
After PUSH AX: SP = 2000H − 2 = 1FFEH.
After PUSH BX: SP = 1FFEH − 2 = 1FFCH.
After one POP: SP = 1FFCH + 2 = 1FFEH.

Conceptual check — Assembly Language Programming

Problem

In a Microprocessors semester or GATE paper you are asked: "State the main assumption, the governing relation, and one practical consequence of assembly language programming." What should a complete answer include?

Exams & GATE

Gaonkar — trace stack after CALL and PUSH sequence.

📖 Standard books (India)

  • Microprocessor Architecture & ProgrammingRamesh Gaonkar

    Read: Syllabus unit

    8085/8086 — widely used in Indian colleges