0% found this document useful (0 votes)
17 views24 pages

Assmebly 8086

This document is a comprehensive guide to 8086 assembly programming using EMU8086, covering the fundamentals of assembly language, the architecture of the 8086 microprocessor, and practical programming examples. It emphasizes the importance of learning assembly for understanding computer architecture, optimizing performance, and engaging in system programming and security research. The guide also includes instructions for using EMU8086, creating simple programs, and understanding assembly language directives and instructions.

Uploaded by

facelivre2021
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)
17 views24 pages

Assmebly 8086

This document is a comprehensive guide to 8086 assembly programming using EMU8086, covering the fundamentals of assembly language, the architecture of the 8086 microprocessor, and practical programming examples. It emphasizes the importance of learning assembly for understanding computer architecture, optimizing performance, and engaging in system programming and security research. The guide also includes instructions for using EMU8086, creating simple programs, and understanding assembly language directives and instructions.

Uploaded by

facelivre2021
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/ 24

A Comprehensive Guide to 8086

Assembly Programming with EMU8086

Introduction to Assembly Language Programming


Assembly language represents the most fundamental level of programming that remains human-
readable. It provides a symbolic representation of the machine code instructions that a computer's
processor can execute directly. Learning assembly language gives you profound insights into how
computers actually work at their core.

Why Learn Assembly Language?


Even in today's world of high-level languages, understanding assembly language offers several
benefits:

1. Deep Understanding of Computer Architecture: Assembly programming reveals exactly


how the CPU processes instructions, manages memory, and interacts with hardware.
2. Performance Optimization: For critical applications where every CPU cycle matters,
assembly language allows fine-grained control over execution.
3. System Programming: Operating systems, device drivers, and embedded systems often
require assembly code for direct hardware manipulation.
4. Security Research: Malware analysis, vulnerability research, and exploit development
require understanding of low-level code execution.
5. Appreciation for Higher-level Languages: After writing assembly code, you'll better
appreciate the conveniences that;qtrix. high-level languages provide!

The 8086 Microprocessor: A Brief History


The Intel 8086, introduced in 1978, was a groundbreaking 16-bit microprocessor that established
the x86 architecture—a foundation that still influences modern computing. The 8086 featured:

• A 16-bit data bus


• 20-bit address bus (allowing access to 1MB of memory)
• 14 internal registers
• Segmented memory model
• Support for approximately 116 instructions

This processor formed the basis for IBM's first personal computer, launching the PC revolution.
Today's complex Intel and AMD processors still maintain compatibility with the original 8086
instruction set, making it an excellent starting point for learning assembly language.

Getting Started with EMU8086


EMU8086 is a powerful tool for learning assembly language programming in a safe, controlled
environment. It combines an editor, assembler, and emulator in one package, making the
development cycle easy and efficient.

What is EMU8086?
EMU8086 is an emulator and integrated development environment (IDE) for the 8086
microprocessor. It allows you to:

• Write assembly language programs with syntax highlighting


• Assemble these programs into machine code
• Run them in a simulated 8086 environment
• Debug programs step-by-step
• Visualize the state of registers, memory, and flags during execution
• Interact with simulated I/O devices

Installing EMU8086
1. Download EMU8086 from an official source
2. Run the installer and follow the installation wizard
3. If prompted for registration, you can use:
• User: ISHAAN,glaitm
• Key: 27R3VDEFYFX4N0VC3FRTQZX

The EMU8086 Interface


When you first open EMU8086, you're presented with a start screen offering several options:

1. Quick Start Tutor: Provides documentation, tutorials, and references for the instruction set
and interrupts
2. Code Examples: Pre-written assembly programs to study and modify
3. Recent Files: Quick access to recently opened .asm files
4. New: Create a new assembly program with different templates

Main Components of the Interface


After opening or creating a file, you'll work with these key components:

• Code Editor: The main area where you write your assembly code, with syntax highlighting
• Menu and Toolbar: Access to commands like assemble, run, and debug
• Registers Window: Displays current values of all CPU registers
• Flags Window: Shows the status of processor flags (Zero, Carry, Sign, etc.)
• Memory Viewer: Allows you to inspect and modify RAM contents
• Stack Window: Shows the contents of the stack segment

Creating Your First Assembly Program


Let's create a simple program that adds two numbers:

1. Click the "New" button on the start screen


2. Select "COM template" for a simple one-segment program
3. You'll see a template with some basic directives

Replace the template with this code:

ORG 100h ; Origin directive for COM programs

; Load two numbers into registers


MOV AX, 5 ; Place value 5 into AX register
MOV BX, 3 ; Place value 3 into BX register

; Add the numbers and store the result in AX


ADD AX, BX ; AX = AX + BX

; Return to operating system


RET

4. Click the "Emulate" button (or press F5) to assemble and run the program
5. The emulator will open, showing registers and memory
6. Click "Single Step" repeatedly to execute the program line by line
7. Watch how the register values change with each instruction

Congratulations! You've written and executed your first assembly program.

Understanding the 8086 Architecture


Before diving deeper into programming, let's understand the architecture we're working with.
Register Set
The 8086 has 14 16-bit registers, grouped as follows:

General Purpose Registers


• AX: Accumulator register - primary register for arithmetic operations
◦ AH (high byte) and AL (low byte) can be accessed separately
• BX: Base register - often used for memory addressing
◦ BH (high byte) and BL (low byte) can be accessed separately
• CX: Count register - used for loop counters and shift/rotate operations
◦ CH (high byte) and CL (low byte) can be accessed separately
• DX: Data register - used for I/O operations and large multiplications/divisions
◦ DH (high byte) and DL (low byte) can be accessed separately

Pointer and Index Registers


• SP: Stack Pointer - points to the top of the stack
• BP: Base Pointer - typically used for accessing parameters and local variables in procedures
• SI: Source Index - used for string operations and memory addressing
• DI: Destination Index - used for string operations and memory addressing

Segment Registers
• CS: Code Segment - points to the segment containing the current code
• DS: Data Segment - points to the segment containing global variables
• SS: Stack Segment - points to the segment containing the stack
• ES: Extra Segment - an additional segment register for string operations

Special Registers
• IP: Instruction Pointer - points to the next instruction to execute (offset in the code segment)
• FLAGS: Contains status and control flags that reflect the result of operations and control CPU
behavior

Memory Model
The 8086 uses a segmented memory model with a total addressable memory of 1MB (2^20
bytes). Memory is divided into segments, with each segment having a maximum size of 64KB
(2^16 bytes).

A memory address consists of two parts:


1. Segment: A 16-bit value that determines the starting point of a memory segment
2. Offset: A 16-bit value that determines the distance from the start of the segment

The physical address is calculated as: Physical Address = Segment × 16 + Offset

In EMU8086, the most common memory model used is the "small" model, which uses one code
segment and one data segment.

Assembly Language Fundamentals


Now let's learn the basic elements of 8086 assembly language.

Directives
Directives are instructions to the assembler rather than to the processor. They don't generate
machine code but guide the assembly process.

Common directives include:

• ORG: Sets the starting address for the code (ORG 100h for COM programs)
• .MODEL: Specifies the memory model (small, medium, large, etc.)
• .STACK: Defines the stack size
• .DATA: Marks the beginning of the data segment
• .CODE: Marks the beginning of the code segment
• DB/DW/DD: Defines byte, word, or double word data
• PROC/ENDP: Marks procedure boundaries
• END: Marks the end of the source file

Data Declaration
You can define variables and constants using these directives:
; Byte declarations
my_byte DB 42 ; Single byte with value 42
my_char DB 'A' ; Single character
my_string DB 'Hello' ; String of characters
bytes DB 1, 2, 3, 4 ; Array of bytes

; Word declarations (16-bit)


my_word DW 1234 ; Single word with value 1234
words DW 100, 200 ; Array of words

; Uninitialized data
buffer DB 100 DUP(?) ; Reserves 100 bytes without initialization

Basic Instructions
The 8086 instruction set has about 116 instructions. Let's cover some fundamental ones:

Data Movement
• MOV: Copies data from source to destination

MOV AX, 1234 ; Load immediate value into AX


MOV BX, AX ; Copy value from AX to BX
MOV CX, [SI] ; Copy value from memory at SI to CX
MOV [DI], DX ; Copy value from DX to memory at DI

Arithmetic Operations
• ADD: Addition

ADD AX, BX ; AX = AX + BX
ADD CX, 5 ; CX = CX + 5

• SUB: Subtraction

SUB AX, BX ; AX = AX - BX
SUB DX, 10 ; DX = DX - 10

• MUL: Unsigned multiplication

MOV AX, 5
MOV BX, 3
MUL BX ; AX = AX * BX (result in AX or DX:AX)
• DIV: Unsigned division

MOV AX, 10
MOV BL, 3
DIV BL ; AL = AX / BL, AH = remainder

Logical Operations
• AND: Bitwise AND

AND AX, BX ; AX = AX AND BX


AND CL, 0Fh ; CL = CL AND 0F (clear upper 4 bits)

• OR: Bitwise OR

OR AX, BX ; AX = AX OR BX
OR DL, 80h ; Set highest bit of DL

• XOR: Bitwise exclusive OR

XOR AX, AX ; Clear AX (faster than MOV AX, 0)


XOR BX, 0FFFFh ; Invert all bits in BX

• NOT: Bitwise NOT

NOT AX ; Invert all bits in AX

Control Flow
• JMP: Unconditional jump

JMP label ; Jump to label

• Conditional jumps: Jump based on flags

JZ label ; Jump if Zero flag is set


JE label ; Jump if Equal (same as JZ)
JNZ label ; Jump if not Zero
JC label ; Jump if Carry flag is set
JNC label ; Jump if no Carry
JA label ; Jump if Above (unsigned comparison)
JB label ; Jump if Below (unsigned comparison)
JG label ; Jump if Greater (signed comparison)
JL label ; Jump if Less (signed comparison)
• LOOP: Decrement CX and jump if CX != 0

MOV CX, 10 ; Initialize counter


loop_start:
; do something
LOOP loop_start ; Repeat until CX = 0

• CALL/RET: Procedure calls

CALL procedure ; Call procedure


; ...
procedure:
; procedure code
RET ; Return to caller

Stack Operations
• PUSH: Push value onto stack

PUSH AX ; Push AX onto stack

• POP: Pop value from stack

POP BX ; Pop top of stack into BX

String Operations
• MOVSB/MOVSW: Move string byte/word
• CMPSB/CMPSW: Compare string byte/word
• STOSB/STOSW: Store AL/AX to string
• LODSB/LODSW: Load string byte/word into AL/AX
• SCASB/SCASW: Scan string for byte/word

Addressing Modes
The 8086 supports various ways to specify operands:

1. Register Addressing: The operand is in a register

MOV AX, BX ; BX is the source, using register addressing

2. Immediate Addressing: The operand is a constant value

MOV CX, 42 ; 42 is an immediate value


3. Direct Addressing: The operand's address is given directly

MOV AX, [1234] ; Get value from memory address DS:1234

4. Register Indirect Addressing: The address is in a register

MOV DX, [BX] ; Get value from address DS:BX

5. Based Addressing: The address is base register + displacement

MOV CL, [BX+5] ; Get value from address DS:(BX+5)

6. Indexed Addressing: The address is index register + displacement

MOV AL, [SI+10]; Get value from address DS:(SI+10)

7. Based Indexed Addressing: The address is base + index + displacement

MOV AH, [BX+SI+2] ; Get value from address DS:(BX+SI+2)

Practical Programming Examples


Let's explore some practical examples to illustrate assembly language programming concepts.

Example 1: Calculating the Sum of an Array

ORG 100h

; Define an array of bytes


array DB 5, 10, 15, 20, 25

; Calculate the sum


MOV SI, OFFSET array ; SI points to the start of the array
MOV CX, 5 ; Loop counter (5 elements)
MOV AL, 0 ; Initialize sum to 0

sum_loop:
ADD AL, [SI] ; Add current element to sum
INC SI ; Move to next element
LOOP sum_loop ; Decrement CX and loop if CX != 0

; Result is now in AL
RET
Example 2: Converting Lowercase to Uppercase

ORG 100h

; Define a string
message DB 'Hello, World!', 0 ; 0 marks the end of string

; Convert to uppercase
MOV SI, OFFSET message ; SI points to the string

convert_loop:
MOV AL, [SI] ; Get current character
CMP AL, 0 ; Check if end of string
JE done ; If yes, we're done

CMP AL, 'a' ; Check if lowercase (below 'a')


JB next_char ; If below 'a', skip conversion
CMP AL, 'z' ; Check if lowercase (above 'z')
JA next_char ; If above 'z', skip conversion

SUB AL, 32 ; Convert to uppercase (ASCII difference)


MOV [SI], AL ; Store back in the string

next_char:
INC SI ; Move to next character
JMP convert_loop ; Repeat for next character

done:
RET

Example 3: Finding the Maximum Value in an Array


ORG 100h

; Define an array of bytes


numbers DB 12, 7, 19, 3, 15, 8, 23, 11

; Find the maximum value


MOV SI, OFFSET numbers ; SI points to the array
MOV CX, 8 ; 8 elements in the array
MOV BL, [SI] ; Initialize max with first element
INC SI ; Move to second element
DEC CX ; Adjust counter

max_loop:
MOV AL, [SI] ; Get current element
CMP AL, BL ; Compare with current max
JLE not_greater ; Jump if not greater
MOV BL, AL ; Update max if greater

not_greater:
INC SI ; Move to next element
LOOP max_loop ; Repeat until done

; Maximum value is now in BL


RET

Example 4: Simple Screen Output


EMU8086 allows you to display text on the screen using DOS interrupts. Here's a simple example:

ORG 100h

; Display a message
MOV AH, 9 ; DOS function: print string
MOV DX, OFFSET message ; DX points to the message
INT 21h ; Call DOS interrupt

RET

; Define the message (must end with '$')


message DB 'Hello from Assembly!$'

Example 5: Reading Keyboard Input


ORG 100h

; Display prompt
MOV AH, 9 ; DOS function: print string
MOV DX, OFFSET prompt ; DX points to the prompt
INT 21h ; Call DOS interrupt

; Read a character
MOV AH, 1 ; DOS function: read character
INT 21h ; AL now contains the character

; Store the character


MOV input, AL ; Save the input

; Display newline
MOV AH, 9
MOV DX, OFFSET newline
INT 21h

; Display message
MOV AH, 9
MOV DX, OFFSET message
INT 21h

; Display the character


MOV AH, 2 ; DOS function: display character
MOV DL, input ; Character to display
INT 21h

RET

prompt DB 'Enter a character: $'


newline DB 13, 10, '$' ; Carriage return, line feed
message DB 'You entered: $'
input DB ? ; Storage for input character

Advanced Assembly Programming Concepts


As you become more comfortable with basic assembly programming, you can explore more
advanced concepts.

Procedures
Procedures allow you to organize code into reusable blocks:

ORG 100h

; Main program
CALL print_message ; Call the procedure
RET ; Return to OS

; Procedure definition
print_message PROC
MOV AH, 9 ; DOS function: print string
MOV DX, OFFSET message ; DX points to the message
INT 21h ; Call DOS interrupt
RET ; Return to caller
print_message ENDP

message DB 'Hello from a procedure!$'

Macros
Macros are like inline functions that get expanded at assembly time:

; Define a macro to print a string


PRINT MACRO string
MOV AH, 9
MOV DX, OFFSET string
INT 21h
ENDM

ORG 100h

; Use the macro


PRINT message1
PRINT message2
RET

message1 DB 'First message$'


message2 DB 'Second message$'

Conditional Assembly
The assembler can include or exclude code based on conditions:
DEBUG EQU 1 ; Set DEBUG flag (1 = on, 0 = off)

ORG 100h

MOV AX, 5
MOV BX, 3
ADD AX, BX ; AX = 8

IF DEBUG
; Debug code only assembled if DEBUG is non-zero
MOV AH, 9
MOV DX, OFFSET debug_msg
INT 21h
ENDIF

RET

debug_msg DB 'Debug: Addition complete$'

Memory Management
Understanding memory organization is crucial for effective assembly programming:
.MODEL SMALL ; Small memory model
.STACK 100h ; 256 bytes for stack

.DATA ; Data segment


count DW 10 ; 16-bit variable
array DB 20 DUP(?) ; 20-byte uninitialized array
name DB 'John', 0 ; Null-terminated string

.CODE ; Code segment


MAIN PROC
; Initialize DS to access data segment
MOV AX, @DATA ; Get data segment address
MOV DS, AX ; Initialize DS register

; Code goes here

; Return to OS
MOV AX, 4C00h ; DOS function: exit program
INT 21h ; Call DOS
MAIN ENDP

END MAIN ; End of program, entry point is MAIN

Debugging Techniques with EMU8086


Debugging is an essential skill for assembly programming. EMU8086 provides powerful debugging
tools to help you find and fix issues in your code.

Step-by-Step Execution
1. Assemble your program by clicking the "Emulate" button
2. Use the "Single Step" button (or F8) to execute one instruction at a time
3. Watch register and memory changes after each instruction
4. Use the "Back" button to step backward if needed

Breakpoints
1. Set breakpoints by clicking on the margin next to instructions
2. Click "Run" to execute up to the breakpoint
3. Continue debugging with "Single Step" or "Run"

Memory and Register Inspection


1. Double-click on any register in the register window to modify its value
2. Use the memory window to inspect and modify memory contents
3. Right-click in the memory window to navigate to specific addresses
4. Watch the stack window to observe push and pop operations

Flags Analysis
The flags window shows the status of processor flags:

• ZF (Zero): Set when the result of an operation is zero


• CF (Carry): Set when an arithmetic operation generates a carry
• SF (Sign): Set when the result of an operation is negative
• OF (Overflow): Set when signed arithmetic results in overflow
• PF (Parity): Set when the result has even parity (even number of 1 bits)
• AF (Auxiliary Carry): Set when there's a carry from bit 3 to bit 4

Understanding how instructions affect these flags helps debug conditional jumps and other
operations.

Working with EMU8086 Virtual Devices


EMU8086 includes several virtual devices to simulate hardware interaction:

Screen Output
The simplest way to display output is through DOS interrupts:

ORG 100h

; Display a character
MOV AH, 2 ; DOS function: display character
MOV DL, 'A' ; Character to display
INT 21h ; Call DOS interrupt

; Display a string
MOV AH, 9 ; DOS function: display string
MOV DX, OFFSET message
INT 21h ; Call DOS interrupt

RET

message DB 'Hello, World!$' ; String must end with '$'


Keyboard Input
For reading input from the keyboard:

ORG 100h

; Read a character
MOV AH, 1 ; DOS function: read character
INT 21h ; Character is returned in AL

; Read a string
MOV AH, 0Ah ; DOS function: buffered input
MOV DX, OFFSET buffer
INT 21h ; Read string into buffer

RET

buffer DB 20, 0 ; Max length and actual length


DB 20 DUP(0); Buffer for input

Graphical Display
EMU8086 can access the video memory for graphics:
ORG 100h

; Set video mode


MOV AH, 0 ; BIOS function: set video mode
MOV AL, 13h ; Mode 13h: 320x200, 256 colors
INT 10h ; Call BIOS interrupt

; Draw a pixel
MOV AH, 0Ch ; BIOS function: draw pixel
MOV AL, 4 ; Color (4 = red)
MOV CX, 100 ; X-coordinate
MOV DX, 100 ; Y-coordinate
INT 10h ; Call BIOS interrupt

; Wait for key press


MOV AH, 0 ; BIOS function: read keyboard
INT 16h ; Call BIOS interrupt

; Return to text mode


MOV AH, 0 ; BIOS function: set video mode
MOV AL, 3 ; Mode 3: 80x25 text
INT 10h ; Call BIOS interrupt

RET

Custom Virtual Devices


EMU8086 includes additional virtual devices that can be accessed through special ports:

• Robot: A simulated robot that can move and interact with its environment
• Stepper Motor: A motor simulation showing rotation
• LED Display: A display of LEDs that can be turned on or off
• Traffic Lights: A simulated traffic intersection

You can access these devices by selecting them from the "Virtual Devices" menu in EMU8086.

Common Interrupts for DOS and BIOS Services


Interrupts provide access to system services. Here are some commonly used ones:

DOS Interrupts (INT 21h)


• Function 1 (AH=1): Read character with echo
• Function 2 (AH=2): Display character
• Function 9 (AH=9): Display string (ending with '$')
• Function 0Ah (AH=0Ah): Buffered input
• Function 4Ch (AH=4Ch): Terminate program

BIOS Interrupts
• INT 10h: Video services
◦ Function 0 (AH=0): Set video mode
◦ Function 0Eh (AH=0Eh): Write character in teletype mode
◦ Function 0Ch (AH=0Ch): Write pixel
• INT 16h: Keyboard services
◦ Function 0 (AH=0): Read keyboard
◦ Function 1 (AH=1): Check for keystroke
• INT 1Ah: Time services
◦ Function 0 (AH=0): Get system time

Practical Programming Projects


Let's explore some complete projects to apply what you've learned.

Project 1: Simple Calculator


This program performs basic arithmetic operations on two numbers:
ORG 100h

; Display welcome message


MOV AH, 9
MOV DX, OFFSET welcome_msg
INT 21h

; Get first number


CALL get_number
MOV BX, AX ; Store first number in BX

; Display operator prompt


MOV AH, 9
MOV DX, OFFSET op_prompt
INT 21h

; Get operator
MOV AH, 1 ; Read character
INT 21h
MOV CL, AL ; Store operator in CL

; Display prompt for second number


MOV AH, 9
MOV DX, OFFSET num2_prompt
INT 21h

; Get second number


CALL get_number
MOV CX, BX ; Move first number to CX
MOV BX, AX ; Store second number in BX

; Perform operation based on operator


CMP CL, '+'
JE do_add
CMP CL, '-'
JE do_sub
CMP CL, '*'
JE do_mul
CMP CL, '/'
JE do_div
JMP invalid_op

do_add:
MOV AX, CX
ADD AX, BX
JMP display_result

do_sub:
MOV AX, CX
SUB AX, BX
JMP display_result

do_mul:
MOV AX, CX
MUL BX ; Result in AX (or DX:AX if large)
JMP display_result

do_div:
MOV AX, CX
MOV CX, BX ; Save divisor in CX
MOV DX, 0 ; Clear DX for division
DIV CX ; AX = DX:AX / CX, remainder in DX
JMP display_result

invalid_op:
MOV AH, 9
MOV DX, OFFSET invalid_msg
INT 21h
JMP done

display_result:
; Display result message
MOV BX, AX ; Save result in BX
MOV AH, 9
MOV DX, OFFSET result_msg
INT 21h

; Display the number


MOV AX, BX ; Get result back
CALL display_number

done:
RET

; Procedure to read a decimal number


get_number PROC
PUSH BX
PUSH CX

MOV BX, 0 ; Initialize result


read_digit:
MOV AH, 1 ; Read character
INT 21h

CMP AL, 13 ; Check for Enter key


JE end_read

CMP AL, '0' ; Check if below '0'


JB invalid_digit
CMP AL, '9' ; Check if above '9'
JA invalid_digit

SUB AL, '0' ; Convert ASCII to binary


MOV CL, AL
MOV AX, 10
MUL BX ; BX * 10
MOV BX, AX
ADD BL, CL ; Add new digit
JNC read_digit ; No overflow, continue

invalid_digit:
MOV AH, 9
MOV DX, OFFSET invalid_digit_msg
INT 21h

end_read:
MOV AX, BX ; Return result in AX
POP CX
POP BX
RET
get_number ENDP

; Procedure to display a decimal number


display_number PROC
PUSH AX
PUSH BX
PUSH CX
PUSH DX

MOV BX, 10 ; Divisor


MOV CX, 0 ; Digit counter

; Handle 0 specially
CMP AX, 0
JNE convert_loop
MOV AH, 2
MOV DL, '0'
INT 21h
JMP end_display

convert_loop:
CMP AX, 0
JE display_loop
MOV DX, 0
DIV BX ; DX:AX / 10, quotient in AX, remainder in DX
PUSH DX ; Save remainder (digit)
INC CX ; Increment digit counter
JMP convert_loop

display_loop:
CMP CX, 0
JE end_display
POP DX ; Get digit
ADD DL, '0' ; Convert to ASCII
MOV AH, 2
INT 21h ; Display digit
DEC CX
JMP display_loop

end_display:
POP DX
POP CX
POP BX
POP AX
RET
display_number ENDP

welcome_msg DB 'Simple Calculator', 13, 10, '$'


op_prompt DB 13, 10, 'Enter operator (+, -, *, /): $'
num1_prompt DB 13, 10, 'Enter first number: $'
num2_prompt DB 13, 10, 'Enter second number: $'
result_msg DB 13, 10, 'Result: $'
invalid_msg DB 13, 10, 'Invalid operator!$'
invalid_digit_msg DB 13, 10, 'Invalid digit!$'

This calculator reads two numbers and an operator, performs the calculation, and displays the
result. It demonstrates input/output operations, arithmetic, procedures, and error handling.
Project 2: String Manipulation Toolkit
This program provides various string operations:

ORG 100h

; Initialize data segment register


MOV AX, @DATA
MOV DS, AX

main_menu:
; Clear screen
CALL clear_screen

; Display menu
MOV AH, 9
MOV DX, OFFSET menu_text
INT 21h

; Get menu choice


MOV AH, 1
INT 21h

; Process menu choice


CMP AL, '1'
JE option_length
CMP AL, '2'
JE option_reverse
CMP AL, '3'
JE option_uppercase
CMP AL, '4'
JE option_count_vowels
CMP AL, '5'
JE exit_program

; Invalid option

You might also like