Sunday, 19 April 2015

nonov

section .data              
            msgmenu db 10,10,"----------------------------MENU----------------------------"
        db 10,10,"1.Non-overlapped with string"
        db 10,"2.Non-overlapped without 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

   
    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

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


%macro dispmsg 2               ;macro for Printing values
   
    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       ;Store choice value in optionmsg buffer


case1:    cmp byte[optionmsg],'1'      ;Non-overlapped block transfer with string
        jne case2  

        dispmsg msgsr1,sr1len        ;Display Source Block before Transfer
        mov rdi,srcblk        
        mov rbp,5
    call displayblock

    dispmsg msgdt1,dt1len        ;Display Destination Block before Transfer
   
        mov rdi,destblk
        mov rbp,5
    call displayblock
           
    mov esi,srcblk               ;Source to destination  Block Transfer
    mov edi,destblk           
        mov ecx,5   

    cld                            ;clear direction flag
    rep movsb                      ;repeat move string byte
   
    dispmsg msgsr2,sr2len          ;Display Source Block After Transfer
    mov rdi,srcblk
        mov rbp,5   
        call displayblock

    dispmsg msgdt2,dt2len         ;Display Destination Block After Transfer
    mov rdi,destblk
    mov rbp,5
        call displayblock


case2:    cmp byte[optionmsg],'2'        ;Non-overlapped block transfer without string
    jne case3
        dispmsg msgsr1,sr1len
    mov rdi,srcblk
        mov rbp,5
    call displayblock

    dispmsg msgdt1,dt1len
    mov rdi,destblk
        mov rbp,5
    call displayblock

    mov esi,srcblk      
    mov edi,destblk     
        mov ecx,5   

   ldt:    mov al,[esi]            ; byte by byte block transfer from source to destination with use of al
    mov [edi],al
    inc esi
    inc edi
    dec ecx
    jnz ldt

    dispmsg msgsr2,sr2len
    mov rdi,srcblk
    mov rbp,5
        call displayblock

    dispmsg msgdt2,dt2len
    mov rdi,destblk
        mov rbp,5   
        call displayblock






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

ext:    mov rax,1            ; exit macro
    mov rbx,0
    int 80h


hextoascii:                ; hextoascii conversion of block data for display
    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:                ; hextoascii conversion of block data for display
       
 l5:    mov eax,[rdi]
    call hextoascii
    dispmsg msgspace,spacelen
    inc rdi
    dec rbp
    jnz l5
    ret

No comments:

Post a Comment