assembly - I am trying to add two values of array and store it in the next array -
the code below suppose sort array named "array". ignore zeros have, add 2 lowest digits , store value new array named "parent". bubble sorting sorts arrays accurately .but not doing suppose to. can please me that?
;huffman seperation lea dx,prompt_1 ;moving address of prompt_1 message call display ;displays prompt_1 message lea si,array ;moving address of array in source index call print_array ;prints whole array on screen lea si,array ;moving address of array in source index call bubble_sort ;sorting algorithm sort array lea dx, prompt_2 ;load , display string prompt_2 call display lea si, array ;set si=offset address of array lea di, parent ;loading address of parent array in di call print_array ;call procedure print_arrayt mov ax, 0 ;used moving address of array during addition mov cx,512 ;512 times calculation should performed lea si,array ;si= pointer array huffloop: calculation: mov bx,[si] ;loading address of array in bx cmp bx,'0' ;if array has 0 value jump skipstep jnz skipstep condition: add si+1,si ;if condition satisfies add first 2 array contents mov di,si+1 ;copying resultant value parent array mov [si],0 ;replacing first lowest value in array 0 lea dx,prompt_1 ;displaying result on screen call display lea si,array call print_array lea si,array call bubble_sort ;doing bubble sorting again repeating step lea dx, prompt_2 ;load , display string prompt_2 call display lea si, array ;set si=offset address of array call print_array ;call procedure print_array mov ax,0 skipstep: add si,2 ;moving next array address jmp calculation ;jumping calculation function jnz huffloop ;jumping huffloop endofhuff:
apart fact code won't assemble, here logical error:
calculation: mov bx,[si] ;loading address of array in bx cmp bx,'0' ;if array has 0 value jump skipstep jnz skipstep condition: ... skipstep:
the jnz
wrong. branch skipstep
taken whenever data not character '0'
, '0'
processed loop. test should be
cmp bx,'0' ;if array has 0 value jump skipstep jz skipstep
Comments
Post a Comment