0% found this document useful (0 votes)
2 views

Assignment

The document provides various assembly language programming examples, including loops, addition, clearing memory, arithmetic operations, and multiplication through repeated addition. It also explains the first and second pass of an assembler, detailing how symbol tables are created and how instructions are processed. Key concepts such as location counters, pseudo instructions, and error diagnostics are highlighted throughout the examples and explanations.

Uploaded by

xbu029
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Assignment

The document provides various assembly language programming examples, including loops, addition, clearing memory, arithmetic operations, and multiplication through repeated addition. It also explains the first and second pass of an assembler, detailing how symbol tables are created and how instructions are processed. Key concepts such as location counters, pseudo instructions, and error diagnostics are highlighted throughout the examples and explanations.

Uploaded by

xbu029
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

Program Loop with Example: A program loop is a sequence of instructions that is repeated until a
certain condition is met. In assembly language programming, loops are implemented using jump
instructions.

Example:

MVI C, 0AH ; Load 10 into register C

LOOP: DCR C ; Decrement C by 1

JNZ LOOP ; Jump to LOOP if C is not zero

HLT ; Halt the program

2. ALP to Add 100 Numbers:

MVI C, 64H ; Load 100 into register C

MVI D, 00H ; Initialize sum to 0

MVI A, 00H ; Initialize A to 0

ADD_LOOP: ADD A ; Add A to accumulator

DCR C ; Decrement C by 1

JNZ ADD_LOOP ; Loop until C is 0

MOV D, A ; Move result to D

HLT ; End of program

3. ALP to Clear Contents from 500H to 5FFH:

LXI H, 0500H ; Load starting address

MVI A, 00H ; Load 0 into accumulator

CLEAR_LOOP: MOV M, A ; Store 0 in memory

INX H ; Increment memory pointer

MOV A, H ; Check if address reached 5FFH

CPI 06H ; Compare high byte with 06H

JNZ CLEAR_LOOP ; Loop if not reached

HLT ; End of program

4. Assembly Program for Given Arithmetic Operations:


MVI H, 00H ; Initialize SUM = 0

MVI L, 00H ; Initialize SUM = 0

MOV A, M ; Load A from memory

INX H ; Increment H

MOV B, A ; Store A in B

MOV A, M ; Load B from memory

ADD B ;A=A+B

MOV M, A ; Store result in SUM

MOV A, M ; Load DIF from memory

SUB C ; DIF = DIF - C

MOV M, A ; Store result in DIF

MOV A, M ; Load SUM from memory

ADD M ; Add DIF to SUM

MOV M, A ; Store result in SUM

HLT ; End of program

5. Explanation of First Pass Assembler (Simplified):


During the first pass of an assembler, the main goal is to create a symbol table that maps user-
defined labels to their corresponding memory addresses.

Key Points:

• A location counter (LC) keeps track of the current memory address of each instruction or
operand.

• The ORG pseudo instruction initializes LC to a specified starting address.

• If ORG is missing, LC starts from 0.

• LC increments by 1 after processing each line of code.

• If a line contains a label, it is stored in the symbol table with its corresponding address.

• If a line contains the ORG instruction, LC is set to the specified number.

• If a line contains the END instruction, the first pass ends.

• No symbol is stored if a label is not present.

Process Summary:

1. LC starts at 0 (or as specified by ORG).

2. Each line is checked for labels and instructions.

3. Labels are stored with their corresponding LC values.

4. LC increments by 1 for each line processed.

5. The first pass ends when the END instruction is encountered.


6. Explanation of Second Pass Assembler (Simplified):

• Uses four key tables:

1. Pseudo Instruction Table: Handles ORG, END, DEC, HEX.

2. MRI Table: Contains 3-bit opcodes for memory-reference instructions.


3. Non-MRI Table: Holds 16-bit codes for register-reference and I/O instructions.

4. Address Symbol Table: Generated in the first pass for symbol-to-address mapping.

• Process Summary:

o LC (Location Counter) starts at 0.

o Lines are analyzed one by one.

o Labels are ignored; the focus is on instructions.

o Pseudo instructions ORG and END control LC and termination.

o Operand pseudo instructions convert operands to binary and store them.

o MRI and Non-MRI tables provide binary instruction codes.

o Address symbols are converted using the address symbol table.

o I (indirect) bit is set to 0 or 1 based on the presence of 'I'.

o Final binary code is stored at the LC-specified memory location.

o LC is incremented by 1 after processing each line.

o Error diagnostics identify invalid symbols not found in MRI or Non-MRI tables.

7. ALP to Subtract Two Numbers:

MVI A, 0AH ; Load first number (10)

MVI B, 05H ; Load second number (5)

SUB B ;A=A-B

HLT ; End of program

8. ALP to Multiply Two Positive Numbers by Repeated Addition:

MVI A, 00H ; Initialize result to 0

MVI B, 03H ; Multiplier (3)

MVI C, 04H ; Multiplicand (4)

MULTIPLY: ADD C ;A=A+C

DCR B ; Decrease multiplier by 1

JNZ MULTIPLY ; Loop until B is 0

HLT ; End of program

Diagram (Repeated Addition Method):


• 4 + 4 + 4 = 12

• Result stored in A after three iterations.

You might also like