assembly

Embed Size (px)

DESCRIPTION

assembly language code for number conversion

Citation preview

  • MPI assignment

    ABDULLAH KAMAL

    FAIZAN ASHRAF

    SALMAN KHAN

  • .model small

    .data

    a db 10,13,'ENTER NUMBER RANGING FROM 0 TO 65535

    = $'

    b db 10,13,'FOR BINARY PRESS 1 ,FOR OCTAL PRESS 2 ,

    FOR HEXA DECIMAL PRESS 3 = $'

    c db 10,13,'RESULT = $'

    d dw ?

    e dw ?

    f db 10,13,'$'

    g db 10,13,'INVALID INPUT THE PROGRAM WILL NOW

    TERMINATE $'

    h db 10

    i db 'TO ENTER NEW NUMBER PRESS 1 ,PRESS ANY

    OTHER KEY TO EXIT $'

    .code

    main proc

    mov ax,@data

    mov ds,ax

    program: ; main program

  • mov ah,09h

    lea dx,f

    int 21h

    mov ah,09h

    lea dx,a

    int 21h

    mov bx,10

    mov ah,01h

    int 21h

    mov ah,00h

    sub al,30h

    mov d,ax

    loop1: ;take input

    mov ah,01h

    int 21h

  • mov ah,00h

    cmp al,0dh ;loop will not break untill enter is

    pressed.

    jne loop2

    jmp next

    loop2:

    sub ax,30h

    mov e,ax

    mov ax,d

    mul bx

    add ax,e

    mov d,ax

    jmp loop1

    next:

    mov ah,09h

    lea dx,f

  • int 21h

    mov ah,09h

    lea dx,b

    int 21h

    mov ah,01h

    int 21h

    mov bh,00h

    mov ah,00h

    mov dx,0

    mov cx,0

    cmp al,31h ;this command will check the user input

    for binary.

    je binary

  • ;this command will check the user input for

    binary.

    cmp al,32h

    je octal

    ;this command will check the user input for

    binary.

    cmp al,33h

    je hexadecimal

    jmp invalid

    binary:

    mov ax,d

    mov bx,02

    jmp conversion

    octal:

    mov ax,d

    mov bx,08

  • jmp conversion

    hexadecimal:

    mov ax,d

    mov bx,16

    jmp conversion

    conversion:

    div bx

    push dx ;here number is pushed in the stack.

    mov dx,0

    inc cx

    cmp ax,0 ;loop will not break untill ax equal to

    zero.

    jnz conversion

    mov ah,09h

    lea dx,f

    int 21h

  • mov ah,09h

    lea dx,c

    int 21h

    display:

    pop dx ;here number poped from the stack.

    cmp dl,h ;if number is greater than 9 then loop

    will break.

    jl dis

    add dl,07

    jmp dis

    dis:

    add dx,30h

    mov ah,2

    int 21h

    loop display

  • jmp pend

    invalid: ;will check that the selscted option is

    valid or not.

    mov ah,09h

    lea dx,g

    int 21h

    pend: ;termination of program

    mov ah,09h

    lea dx,f

    int 21h

    mov ah,09h

    lea dx,i

    int 21h

    mov ah,09h

  • lea dx,f

    int 21h

    mov ah,01h

    int 21h

    cmp al,31h

    je program

    mov ah,4ch

    int 21h

    main endp

    end main