nasm - Unable to do overlap block transfer in Assembly -


i have made program in assembly language(nasm) overlap block transfer i.e., if 1 of array contains '10, 20, 30, 40, 50'(without quotes) after overlapping of example 2 elements resulting array should contain '10, 20, 10, 20, 30, 40, 50'(without quotes). problem when display resultant array shows '10, 20, 10, 20, 30'(without quotes). unable figure out problem. below shown code. appreciated.

%macro disp 2                               ; display macro mov rax,1 mov rdi,1 mov rsi,%1 mov rdx,%2 syscall %endm  %macro accept 2                             ; accept data mov rax,0 mov rdi,0 mov rsi,%1 mov rdx,%2 syscall %endm  global _start             section .data                               ; data section arr db 10h,20h,30h,40h,50h msg1: db "",10,"input array is",10 len1: equ $-msg1 msg2: db "",10,"output array is",10 len2: equ $-msg2 msg3: db "enter number overlapped",10 len3: equ $-msg3  section .bss                                ; bss section arr1 resb 10 ar1 resb 10 ar2 resb 10 cn resb 2    section .text                               ; text section _start:                                 ; tell linker entry point  disp msg3,len3                                       accept cn,2                         ; accept no. of overlaps done user  mov cl,[cn]                         ; convert cn ascii sub cl,'0'                          ; decimal  mov rsi,arr mov rdi,arr1   up: mov al,[rsi]                            ; copy contents arr arr1 cn times mov [rdi],al inc rsi inc rdi dec cl jnz  mov rsi,arr                         ; copy contents again starting mov cl,5  up_a:   mov al,[rsi] mov [rdi],al inc rsi inc rdi dec cl jnz up_a  mov rsi,arr                         ; convert ascii mov rdi,ar1 mov rdx,5 call asci  mov rsi,arr1                            ; convert ascii mov rdi,ar2 mov rdx,10 call asci  disp msg1,len1 disp ar1,10  disp msg2,len2 disp ar2,10  mov rax,60 mov rdi,0 syscall   asci:    up1:    mov al,[rsi]        ;move first element pointed rsi al register     mov cl,2        ;the loop counter (there 2 digits)  up2:    rol al,4        ; rotate contents of al 4 bits left.                     ; significant bit in                     ; least significant bit of al. done because                     ; want print significant digit first.      mov bl,al       ; make copy of rotated version of al.     , al,0fh      ; keep least significant bit of al , set other                     ; bits of al 0.     cmp al,09h      ; al in range 0..15. greater 9?     ja dn1          ; ..if so, jump dn1.     add al,30h      ; al in range 0..9. characters '0'..'9' encoded                     ; 30h..39h in ascii, add 30h convert character.     jmp dn2         ; we're done case.  dn1:    add al,37h      ; al in range 10..15. characters 'a'..'f' encoded                         ; 41h..46h in ascii, add 37h convert character.  dn2:   mov [rdi],al     ; store character in buffer pointed rdi.     mov al,bl       ; restore al value had right after rol. on                     ; next iteration we'll processing                     ; second significant bit, , on.     inc rdi         ; increment buffer pointer.     dec cl          ; decrement loop counter.     jnz up2         ; repeat 2 digits.          inc rsi         ; rsi points next location     dec rdx         ; decrement loop counter     jnz up1         ; repeat 5 array elements  ret 

your overlapped copy works fine. doesn't work how you're calling display routine.

first, have allocated 10 bytes output, when you're copying hex representation of 10-byte array (so need 20 bytes!)

second, printing 10 bytes. since we're changing length 20, should change print length too.

here change in unified diff form:

--- orig.s  2016-01-16 19:55:33.268099503 +0000 +++ modified.s  2016-01-16 19:58:24.952600505 +0000 @@ -28,7 +28,7 @@  section .bss                                ; bss section  arr1 resb 10  ar1 resb 10 -ar2 resb 10 +ar2 resb 20  cn resb 2   @@ -77,7 +77,7 @@  disp ar1,10   disp msg2,len2 -disp ar2,10 +disp ar2,20   mov rax,60  mov rdi,0 

despite having wrong length array , printing of array, had right lengths in call asci function.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -