Sunday, 19 April 2015

ov

section .data               
            msgmenu db 10,10,"----------------------------MENU----------------------------"
       
        db 10,"1.overlapped without string"
        db 10,"2.overlapped with string"
        db 10,"3.Exit"
        db 10,"Enter your choice:-"
   
        menulen equ $-msgmenu

   
    msgsr1 db "Contents of source block before data transfer",10
    sr1len equ $-msgsr1
         
    msgdt1 db 10,"Contents of destination block before data transfer",10
    dt1len equ $-msgdt1

    msgsr2 db 10,"Contents of source block after data transfer",10
    sr2len equ $-msgsr2

    msgdt2 db 10,"Contents of destination block after data transfer",10
    dt2len equ $-msgdt2

    msgspace db " "
    spacelen equ $-msgspace

    msgpos db 10, "Enter position",10
    msgposlen equ $-msgpos

    srcblk db 01h,02h,03h,04h,05h
    destblk times 5 db 00

    sdblk db 01h,02h,03h,04h,05h,00h,00h,00h,00h,00h
        cnt equ 05

section .bss        
   
optionmsg resb 2
optlen: equ $-optionmsg
buffno resb 3
buffnolen: equ $-buffno
dispnum resb 2
position resb 2
positionlen: equ $-position
pos resb 1

%macro read 2               
     mov rax,3        
     mov rbx,0        
     mov rcx,%1       
     mov edx,%2       
     int 80h
   
%endmacro           


%macro dispmsg 2              
   
    mov rax,4   
    mov rbx,1   
    mov rcx,%1   
    mov rdx,%2   
    int 80h       
%endmacro

section .text                      
global _start
_start:
   
menu:    dispmsg msgmenu,menulen 
       
    read optionmsg,optlen      




case1:    cmp byte[optionmsg],'1'           
    jne case2
        
    dispmsg msgdt1,dt1len
    mov rdi,sdblk
        mov rbp,10
    call displayblock

        dispmsg msgpos,msgposlen      
        read position,positionlen
         call conv                     
        mov [pos],bl 
        mov esi,sdblk+4                        
        mov edi,esi
        add edi,[pos]                 
        dec edi
        mov ecx,cnt

l7:
        mov al,[esi]
        mov [edi],al
        dec edi
        dec esi
        dec ecx
        jnz l7

        mov rdi,sdblk
        mov rbp,10
        call displayblock
   

case2:    cmp byte[optionmsg],'2'           
    jne case3
        dispmsg msgdt1,dt1len
    mov rdi,sdblk
        mov rbp,10
    call displayblock
   
    dispmsg msgpos,msgposlen
        read position,positionlen
        
        call conv
        mov [pos],bl 
    mov esi,sdblk+4               
    mov edi,esi
    add edi,[pos]
   
        dec edi
    mov ecx,cnt
        std
        rep movsb
        mov rdi,sdblk
        mov rbp,10
        call displayblock
   


case3:    cmp byte[optionmsg],'3'
    je ext
    jmp menu

ext:    mov rax,1            
    mov rbx,0
    int 80h



hextoascii:              
    mov rcx,02
    mov rsi,dispnum+1
    
l2:    mov rdx,00
    mov rbx,16
    div rbx
    cmp dl,09h
    jbe skip2
    add dl,07h

 skip2:    add dl,30h
    mov [rsi],dl
    dec rsi
    dec rcx
    jnz l2
    dispmsg dispnum,2
    ret

displayblock:               
       
 l5:    mov eax,[rdi]
    call hextoascii
    dispmsg msgspace,spacelen
    inc rdi
    dec rbp
    jnz l5
    ret

conv:

    mov bl,00               
    mov rcx,01
    mov rsi,position
   
L1:
    shl bl,4
    mov al,[rsi]
    cmp al,39h
    jbe skip
    sub al,7h

    skip:sub al,30h
    add bl,al
    ret

No comments:

Post a Comment