0% found this document useful (0 votes)
3 views17 pages

CSB23044 Lab09

The document contains an assembly language program for the 8086 microprocessor that manages student records, calculates totals and averages of marks, and includes a procedure for inputting records from the keyboard. It defines constants for the number of records and fields, and utilizes various registers for arithmetic operations. Additionally, it includes observations on variable locations and values, as well as learning outcomes related to addressing modes and division operations in assembly language.

Uploaded by

csb23044
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views17 pages

CSB23044 Lab09

The document contains an assembly language program for the 8086 microprocessor that manages student records, calculates totals and averages of marks, and includes a procedure for inputting records from the keyboard. It defines constants for the number of records and fields, and utilizes various registers for arithmetic operations. Additionally, it includes observations on variable locations and values, as well as learning outcomes related to addressing modes and division operations in assembly language.

Uploaded by

csb23044
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

CO215, Assignment 9

Roll number: CSB23044

Name: Sagar Gogoi

Session: Spring, Year: 2025


Exercises:

.MODEL SMALL

.STACK 100H

.DATA

No_Records EQU 5

No_Fields EQU 7

Bytes_Record EQU No_Fields * 2

Subjects db 3

Marks_Records DW 01, 22, 66, 54, 75, 00, 00

DW 02, 21, 70, 67, 77, 00, 00

DW 03, 21, 55, 60, 65, 00, 00

DW 04, 22, 75, 66, 83, 00, 00

DW 05, 21, 49, 59, 69, 00, 00 ;field 1: roll, field 2: age, field 3-5: marks,

; field 6: total, field 7: average

Subject_Av DW ?,?,?,?,?,?,?

Output_Msg1 DB 'Roll No $'

Output_Msg2 DB ': Total- $'

Output_Msg3 DB ' Average- $'

nwln db 10, 13, '$'

ten db 10
hun db 100

.CODE

main PROC

.STARTUP

mov cx, No_Records

sub bx, bx

Repeat1:

sub ax, ax

add ax, Marks_Records[bx+4]

add ax, Marks_Records[bx+6]

add ax, Marks_Records[bx+8]

mov Marks_Records[bx+10], ax

div Subjects

sub ah, ah

mov Marks_Records[bx+12], ax

add bx, Bytes_Record

loop Repeat1

mov cx, No_Records

sub bx, bx

sub dx, dx

Repeat2:

lea dx, nwln

mov ah, 09h

int 21h

lea dx, Output_Msg1

mov ah, 09h


int 21h

pusha ; save all register values in stack so that they can be restored after printing

; integer is done

mov ax, Marks_Records[bx] ; to print roll

div ten

mov bx, ax ; saving value of ax in bx in order to avoid being overwritten

mov dl, al

add dl, 30h

mov ah, 02h

int 21h

mov dl, bh ; bx = ax thus bh = ah that is bh = remainder of the div operation

add dl, 30h

mov ah, 02h

int 21h

popa ; restore all register values

lea dx, Output_Msg2

mov ah, 09h

int 21h

pusha

mov ax, Marks_Records[bx+10] ;to print total

div hun

mov bx, ax

mov dl, al
add dl, 30h

mov ah, 02h

int 21h

mov ah, 0

mov al, bh

div ten

mov bx, ax

mov dl, al

add dl, 30h

mov ah, 02h

int 21h

mov dl, bh

add dl, 30h

mov ah, 02h

int 21h

popa ; restore all register values

lea dx, Output_Msg3

mov ah, 09h

int 21h

pusha

mov ax, Marks_Records[bx+12] ; to print average

div ten

mov bx, ax

mov dl, al
add dl, 30h

mov ah, 02h

int 21h

mov dl, bh

add dl, 30h

mov ah, 02h

int 21h

popa ; restore all register values

lea dx, nwln

mov ah, 09h

int 21h

add bx, Bytes_Record ; to point bx to next record

loop Repeat2

; .EXIT

mov ah ,4ch

mov al ,0

int 21h

main ENDP

END main

Add a procedure to the program to read in the Marks_Records from the keyboard and repeat

the exercises.

.MODEL SMALL

.STACK 100H

.DATA
No_Records EQU 5

No_Fields EQU 7

Bytes_Record EQU No_Fields * 2

Subjects DB 3

Marks_Records DW 01, 22, 66, 54, 75, 00, 00

DW 02, 21, 70, 67, 77, 00, 00

DW 03, 21, 55, 60, 65, 00, 00

DW 04, 22, 75, 66, 83, 00, 00

DW 05, 21, 49, 59, 69, 00, 00

Output_Msg1 DB 'Roll No $'

Output_Msg2 DB ': Total- $'

Output_Msg3 DB ' Average- $'

Input_Msg1 DB 'Enter student data (Roll Age Mark1 Mark2 Mark3): $'

Input_Space DB ' $'

nwln DB 10, 13, '$'

ten DB 10

hun DB 100

.CODE

main PROC

.STARTUP

CALL InputRecords
mov cx, No_Records

sub bx, bx

Repeat1:

sub ax, ax

add ax, Marks_Records[bx+4]

add ax, Marks_Records[bx+6]

add ax, Marks_Records[bx+8]

mov Marks_Records[bx+10], ax

div Subjects

sub ah,ah

mov Marks_Records[bx+12], ax

add bx, Bytes_Record

loop Repeat1

mov cx, No_Records

sub bx, bx

sub dx, dx

Repeat2:

lea dx, nwln

mov ah, 09h

int 21h

lea dx, Output_Msg1

mov ah, 09h

int 21h
push ax

push bx

push cx

push dx

push sp

push si

mov ax, Marks_Records[bx]

div ten

mov bx, ax

mov dl, al

add dl, 30h

mov ah, 02h

int 21h

mov dl, bh

add dl, 30h

mov ah, 02h

int 21h

pop si

pop sp

pop dx

pop cx

pop bx

pop ax

lea dx, Output_Msg2


mov ah, 09h

int 21h

push ax

push bx

push cx

push dx

push sp

push si

mov ax, Marks_Records[bx+10]

div hun

mov bx, ax

mov dl, al

add dl, 30h

mov ah, 02h

int 21h

mov ah, 0

mov al, bh

div ten

mov bx, ax

mov dl, al

add dl, 30h

mov ah, 02h

int 21h

mov dl, bh
add dl, 30h

mov ah, 02h

int 21h

pop si

pop sp

pop dx

pop cx

pop bx

pop ax

lea dx, Output_Msg3

mov ah, 09h

int 21h

push ax

push bx

push cx

push dx

push sp

push si

mov ax, Marks_Records[bx+12]

div ten

mov bx, ax

mov dl, al

add dl, 30h


mov ah, 02h

int 21h

mov dl, bh

add dl, 30h

mov ah, 02h

int 21h

pop si

pop sp

pop dx

pop cx

pop bx

pop ax

lea dx, nwln

mov ah, 09h

int 21h

add bx, Bytes_Record

dec cx

cmp cx,0

je Exit_loop

jmp Repeat2

Exit_loop:

mov ah, 4ch


mov al, 0

int 21h

main ENDP

InputRecords PROC

PUSH AX

PUSH BX

PUSH CX

PUSH DX

PUSH SI

MOV CX, No_Records

MOV BX, 0

InputLoop:

LEA DX, nwln

MOV AH, 09H

INT 21H

LEA DX, Input_Msg1

MOV AH, 09H

INT 21H

CALL InputNumber

MOV Marks_Records[BX], AX
LEA DX, Input_Space

MOV AH, 09H

INT 21H

CALL InputNumber

MOV Marks_Records[BX+2], AX

LEA DX, Input_Space

MOV AH, 09H

INT 21H

CALL InputNumber

MOV Marks_Records[BX+4], AX

LEA DX, Input_Space

MOV AH, 09H

INT 21H

CALL InputNumber

MOV Marks_Records[BX+6], AX

LEA DX, Input_Space

MOV AH, 09H

INT 21H

CALL InputNumber

MOV Marks_Records[BX+8], AX
MOV WORD PTR Marks_Records[BX+10], 0

MOV WORD PTR Marks_Records[BX+12], 0

ADD BX, Bytes_Record

LOOP InputLoop

POP SI

POP DX

POP CX

POP BX

POP AX

RET

InputRecords ENDP

InputNumber PROC

PUSH BX

PUSH DX

MOV AH, 01H

INT 21H

SUB AL, '0'

MOV BL, 10

MUL BL

MOV BH, AL

MOV AH, 01H


INT 21H

SUB AL, '0'

ADD BH, AL

MOV AX, 0

MOV AL, BH

POP DX

POP BX

RET

InputNumber ENDP

END main

Observations:

Variables:

Name No of Location Initial value Step no Final value


Bytes after which
value does
not change
No_Records 2 Constant 5 0(constant) 5
No_Fields 2 Constant 7 0(constant) 7
Bytes_Record 2 Constant 14(7x2) 0(constant) 14
Marks_Records 70 Data Array of Student Records After Contains updated totals
Segment Repeat 1 and averages
loop
Subject_Av 14 Data Undefined Not Used Undefined
Segment

Learning Outcome:

1. Instruction structures in µP 8086 ALP for based-indexed addressing: Based-Indexed addressing


in 8086 uses a combination of base register (BX or BP), index register (SI or DI), and optional
displacement to calculate effective memory addresses.
Format: instruction operand, [base_register + index_register + displacement]

Key characteristics:

● Valid base registers: BX, BP


● Valid index registers: SI, DI
● Displacement: Optional 8-bit or 16-bit value
● Default segment: DS (when using BX), SS (when using BP)

Examples:

assembly

2. MOV AX, [BX + SI] ; No displacement


3. MOV CL, [BP + DI + 5] ; With 8-bit displacement

MOV DX, [BX + SI + 1000h] ; With 16-bit displacement

Applications: Efficient for accessing array elements, data structures, and stack parameters where
complex address calculations are needed.

2. Use of various registers in the division instruction operation in µP 8086: The 8086 division
operations (DIV/IDIV) utilize specific registers depending on operand size:

For 8-bit division:

● Dividend: AX register (16-bit)


● Divisor: 8-bit register or memory location
● Quotient: AL register
● Remainder: AH register

For 16-bit division:

● Dividend: DX
register pair (32-bit value)
● Divisor: 16-bit register or memory location
● Quotient: AX register
● Remainder: DX register

Examples:

assembly

; 8-bit division
MOV AX, 250 ; Dividend

DIV BL ; Divide by BL, result: AL=quotient, AH=remainder

; 16-bit division

MOV AX, 4000 ; Low word of dividend

MOV DX, 0 ; High word of dividend

DIV CX ; Divide by CX, result: AX=quotient, DX=remainder

You might also like