0% found this document useful (0 votes)
131 views10 pages

Microprocessor-Lab-x86-asm: Name "Hello-World" Org

The document describes 11 assembly language programs written using emu8086 and masm for the 8086 microprocessor. The programs include: 1) A colored "Hello World" program that prints the message in different colors. 2) Division of 16-bit by 8-bit and 32-bit by 16-bit numbers. 3) Multiplication of 8-bit by 8-bit and 32-bit by 16-bit numbers. 4) Programs to display and read characters and strings. 5) A program that calculates the sum of numbers in a loop. 6) A program that checks if a number is even or odd. 7) A program that finds the smallest and largest

Uploaded by

Test Case
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)
131 views10 pages

Microprocessor-Lab-x86-asm: Name "Hello-World" Org

The document describes 11 assembly language programs written using emu8086 and masm for the 8086 microprocessor. The programs include: 1) A colored "Hello World" program that prints the message in different colors. 2) Division of 16-bit by 8-bit and 32-bit by 16-bit numbers. 3) Multiplication of 8-bit by 8-bit and 32-bit by 16-bit numbers. 4) Programs to display and read characters and strings. 5) A program that calculates the sum of numbers in a loop. 6) A program that checks if a number is even or odd. 7) A program that finds the smallest and largest

Uploaded by

Test Case
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/ 10

Digital Assignment – 2

CSE2006 – Microprocessor and Interfacing Lab


Name: Shankha Shubhra Sarkar
ID: 18BCE2453

Sample programs using emulator emu8086 and masm (using Dosbox) on


laptop. Many programs are added into my GitHub Repo: Microprocessor-
Lab-x86-asm

1. Colored HelloWorld.
Code:
name "hello-world"

org 100h

; set video mode    
mov ax, 3     ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3)
int 10h       ; do it!

; cancel blinking and enable all 16 colors:
mov ax, 1003h
mov bx, 0
int 10h

; set segment register:
mov     ax, 0b800h
mov     ds, ax

; print "hello world"
; first byte is ascii code, second byte is color code.

mov [02h], 'H'

mov [04h], 'e'

mov [06h], 'l'

mov [08h], 'l'
mov [0ah], 'o'

mov [0ch], ','

mov [0eh], 'W'
 
mov [10h], 'o'

mov [12h], 'r'

mov [14h], 'l'

mov [16h], 'd'

mov [18h], '!'

; color all characters:
mov cx, 12  ; number of characters.
mov di, 03h ; start from byte after 'h'

c:  mov [di], 11101100b   ; light red(1100) on yellow(1110)
    add di, 2 ; skip over next ascii code in vga memory.
    loop c

; wait for any key press:
mov ah, 0
int 16h

ret

2. Division 16bit/8bit.
Code:
data segment
a dw ?
b db ?
c db ?
data ends

code segment
assume ds:data, cs:code

start:  mov ax, data
    mov ds, ax

    mov ax, a
    mov bl, b
    div bl
    mov c, al
    mov c+1, ah

    mov ah, 4ch
    int 21h
code ends
end start

3. Division 32bit/16bit.
Code:
data segment
a0 dw ?
a1 dw ?
b dw ?
c dw ?
data ends

code segment
assume ds:data, cs:code

start:  mov ax, data
    mov ds, ax

    mov ax, a0
    mov dx, a1
    mov bx, b
    div bx
    mov c, ax
    mov c+2, dx

    mov ah, 4ch
    int 21h
code ends
end start
4. Multiplication 8bit*8bit.
Code:
data segment
a db 005H
b db 006H
c db ?
data ends

code segment
assume ds:data, cs:code

start:  mov ax, data
    mov ds, ax

    mov al, a
    mov bl, b
    mul bl
    mov c, al
    mov c+1, ah

    mov ah, 4ch
    int 21h
code ends
end start

5. Multiplication 32bit*16bit.
Code:
data segment
a0 dw ?
a1 dw ?
b dw ?
c dw ?
data ends

code segment
assume ds:data, cs:code

start:  mov ax, data
    mov ds, ax

    mov ax, a0
    mov bx, b
    mul bx
    mov c, ax
    mov c+2, dx
    mov ax, a1
    mul bx
    add c+2, ax
    adc c+4, dx

    mov ah, 4ch
    int 21h
code ends
end start

6. Display a Char.
Code:
.model small
.stack 100h

.code
   main proc
     mov ah, 2          
     mov dl, "A"
     int 21h            ;display the character A

     mov ah, 4ch        
     int 21h            ;return control to os
   main endp
end main

7. Read and Display Char.


Code:
.model small
.stack 100h 

.code
   main proc
     mov ah, 1                    
     int 21h                      ;read a character

     mov bl, al                   ;store input character into bl
     mov ah, 2                    
     mov dl, 0dh          
     int 21h                      ;cursor to begining

     mov dl, 0ah                  
     int 21h                      ;new line

     mov ah, 2                      
     mov dl, bl
     int 21h                      ;display the character stored in bl 

     mov ah, 4ch                  
     int 21h                      ;return control to os

   main endp
end main

8. Display String.
Code:
.model small
.stack 100h

.data
    str1 db "Welcome to dronegj github repo $"
    str2 db "This is a second string $"

.code
    main proc
        mov ax, @data       ;load data
        mov ds, ax

        lea dx, str1           
        mov ah, 9            
        int 21h             ;load & display the first string

        mov ah, 2            
        mov dl, 0dh
        int 21h             ;cursor to begining

        mov dl, 0ah          
        int 21h             ;new line
        lea dx, str2         
        mov ah, 9
        int 21h             ;load & display the second string

        mov ah, 4ch         
        int 21h
    main endp               ;return control to os
end main

9. Sum using Loops.


Code:
include "emu8086.inc"
org 100h

    range dw ?
    res dw ?

    mov dx, offset msg
    mov ah, 9 
    int 21h                 ;print title

    mov dx, offset msg1    
    mov ah, 9
    int 21h                 ;ask range

    call scan_num
    mov range, cx           ;store range

    mov res, 0              
    mov bx, 1

    jmp label

label:
    mov dx, offset msg2
    mov ah, 9
    int 21h                 ;print ask values

    call scan_num           ;get values

    add res, cx             ;add current input with result
    inc bx                  ;increment of bx
                        
    cmp range, bx           ;compare and substract bx from range
    jb exit                 ;jump if bx is below range

    jmp label               ;else jump to print result
       
exit:
    mov ax,res 
    lea si, msg3
    call print_string
    call print_num  
                
    mov ah, 0
    int 16h                 ; wait for any key press to exit
        
ret                                

    msg db "Addition in Loop $"
    msg1 db 13,10, "Enter Total No of Numbers: $"
    msg2 db 13,10, "Number to Add : $"
    msg3 db 13,10, "Total Sum: ", 0 
    
define_scan_num
define_print_num
define_print_num_uns
define_print_string                          

10. Even or Odd number.


Code:
include "emu8086.inc"
org 100h
                
    num dw ?
    
    mov dx, offset msg
    mov ah, 9 
    int 21h                 ;print title
                                         
    mov dx, offset msg1    
    mov ah, 9
    int 21h                 ;ask number
    
    call scan_num
    mov num, cx
                                         
    mov ax, num
    and ax, 1
    xor ax, 1
    
    jz oddcheck
    
evencheck:
    lea si, msg2
    call print_string
    jmp exit
    
oddcheck:
    lea si, msg3
    call print_string   

exit:               
    mov ah, 0
    int 16h                 ; wait for any key press:    
ret                                

    msg db "Check Number Even/Odd $"
    msg1 db 13,10, "Enter your Number: $"
    msg2 db 13,10, "Number is Even. ", 0
    msg3 db 13,10, "Number is Odd. ", 0  

define_scan_num
define_print_num
define_print_num_uns
define_print_string

end                   

11. Smallest and largest from array.


Code:
data segment
a db 1,2,5,6,4,8              ;array of numbers
data ends
    
code segment
      assume ds:data,cs:code
start:
      mov ax,data
      mov ds,ax
      mov cx,0000
      mov cl,06
      lea bx,a
      mov al,00
      mov ah,byte ptr[bx]
      
   l1:cmp al,byte ptr[bx]
      jnc l2
      
      mov al,byte ptr[bx]     ;store largest value at al
      
   l2:cmp ah,byte ptr[bx]
      jc l3               
      
      mov ah,byte ptr[bx]     ;store smallest value at ah
      
   l3:inc bx
      dec cl
      cmp cl,00
      jnz l1  
       
code ends 
end start

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy