0% found this document useful (0 votes)
4 views5 pages

Shot Booty

The document covers various programming concepts including subroutines, stacks, algorithms, and different architectures such as MIPS and iAPX. It provides definitions, key operations, and code examples for each topic, illustrating how to implement them in assembly language. Additionally, it discusses software and hardware interrupts, along with memory display and number printing techniques.

Uploaded by

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

Shot Booty

The document covers various programming concepts including subroutines, stacks, algorithms, and different architectures such as MIPS and iAPX. It provides definitions, key operations, and code examples for each topic, illustrating how to implement them in assembly language. Additionally, it discusses software and hardware interrupts, along with memory display and number printing techniques.

Uploaded by

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

COAL Lecture 13

1. Subroutines
Definition: Subroutines are blocks of reusable code that perform a specific task. They
improve modularity and reduce redundancy in programs.
Key Concepts:
CALL: Transfers control(data) to the subroutine and saves the return address
on the stack.
RET: Returns control to the instruction after the CALL.

Code Example:
; Subroutine: Adding two numbers
[org 0x0100]
start:
mov ax, 5 ; First number
mov bx, 3 ; Second number
call add_numbers ; Call subroutine
mov ah, 0x4C ; Terminate program
int 0x21

add_numbers:
add ax, bx ; Add BX to AX
ret ; Return to caller

2. Stacks
Definition: A stack is a FILO (First-In-Last-Out) data structure used to temporarily
store data such as return addresses, parameters, and registers.
Key Operations:
PUSH: Adds data to the stack.
POP: Removes data from the stack.

Code Example:
; Using the stack to save and restore a value
[org 0x0100]
start:
mov ax, 1234h ; Load value into AX
push ax ; Save AX to stack
mov ax, 5678h ; Load new value into AX
pop bx (1234h) ; Restore original AX value into BX
mov ah, 0x4C ; Terminate program
int 0x21
3. Algorithms
Bubble Sort
Definition: A sorting algorithm that repeatedly steps through the list, compares
adjacent elements, and swaps them if they are in the wrong order.
Code Example:
; [org 0x0100] ; Origin address for a COM program

data: dw 5, 3, 8, 4, 2, 0 ; Array to be sorted, terminated with a 0

start:
mov bx, data ; Load the starting address of the array into BX
mov cx, 5 ; Load the array size (number of elements) into CX

outer_loop:
mov si, 0 ; Initialize index (SI) to 0
mov byte [swap], 0 ; Reset swap flag to 0

inner_loop:
mov ax, [bx + si] ; Load the current element into AX
cmp ax, [bx + si + 2] ; Compare AX with the next element
jbe no_swap ; If AX <= next element, no swapping is needed

xchg ax, [bx + si + 2] ; Swap AX with the next element


mov [bx + si], ax ; Write the swapped value back to the current
position
mov byte [swap], 1 ; Set swap flag to indicate a swap occurred

no_swap:
add si, 2 ; Move to the next element (2 bytes per element)
cmp si, cx ; Check if we reached the end of the array
jne inner_loop ; If not, continue the inner loop

cmp byte [swap], 1 ; Check if any swaps were made


je outer_loop ; If yes, repeat the outer loop

mov ah, 0x4C ; DOS interrupt to terminate the program


int 0x21

swap:
db 0 ; Swap flag (1 if a swap occurred, 0 otherwise)

Booth's Multiplication
Definition: A multiplication algorithm for signed binary numbers that uses arithmetic
shifts and additions to improve efficiency.
Code Example:
(Refer to Lecture 13 for algorithm logic and flowchart implementation in assembly.)
COAL Lecture 14
Display Memory
Definition: VGA text mode maps characters and their attributes to screen memory.
The base address is 0xB8000.
Code Example:
; Displaying 'A' at top-left corner
[org 0x0100]
start:
mov ax, 0xB800 ; VGA base address
mov es, ax
mov di, 0 ; Top-left corner
mov al, 'A' ; Character to display
mov ah, 0x07 ; White text on black background
mov [es:di], ax ; Write to VGA memory

mov ah, 0x4C


int 0x21

2. Number Printing
Definition: Converts binary numbers to ASCII for display.
Code Example:
; Printing a number
[org 0x0100]
number: dw 1234
start:
mov ax, [number]
mov bx, 10
convert:
xor dx, dx ; Clear DX
div bx ; Divide AX by 10
add dl, '0' ; Convert remainder to ASCII
push dx ; Push ASCII digit onto stack
test ax, ax ; Check if quotient is zero
jnz convert
print:
pop dx
; Add your logic to display DX
mov ah, 0x4C
int 0x21

COAL Lecture 15
1. Software Interrupts
Definition: Software interrupts (e.g., INT n) allow programs to call predefined
routines for system services.
Code Example:
; Using BIOS interrupt to print a character
[org 0x0100]
start:
mov ah, 0x0E ; BIOS teletype function
mov al, 'A' ; Character to display
int 0x10 ; Call BIOS interrupt
mov ah, 0x4C
int 0x21

COAL Lecture 16
1. Hardware Interrupts
Definition: Real-time interrupts triggered by external devices, like keyboards or
timers.
Code Example:
; Handling keyboard interrupts
[org 0x0100]
start:
in al, 0x60 ; Read key press from keyboard
mov [keybuffer], al
mov ah, 0x4C
int 0x21
keybuffer db ?

COAL Lecture 17
1. MIPS Architecture
Definition: A RISC-based architecture with load/store design principles and simple
instruction sets.
Code Example:
# MIPS Assembly: Adding two numbers
.data
num1: .word 5
num2: .word 3
result: .space 4
.text
main:
lw $t0, num1 # Load num1 into $t0
lw $t1, num2 # Load num2 into $t1
add $t2, $t0, $t1 # Add $t0 and $t1
sw $t2, result # Store result
li $v0, 10 # Exit
syscall
COAL Lecture 18
1. iAPX 88/188 Architecture
Definition: Intel 8088 and 80188 are 16-bit microprocessors with 8-bit external data
buses for cost efficiency.
Code Example:
; 8088 Data Movement Example
[org 0x0100]
start:
mov ax, 1234h ; Load value into AX
mov bx, ax ; Move AX to BX
mov ah, 0x4C
int 0x21

You might also like