Assembly 我尝试将数组的两个值相加,并将其存储在下一个数组中
下面的代码假设对名为“array”的数组进行排序。然后忽略它所有的零,添加两个最低的数字,并将值存储到名为“parent”的新数组中。冒泡排序可以精确地对数组进行排序,但它并没有达到预期的效果。有人能帮我吗Assembly 我尝试将数组的两个值相加,并将其存储在下一个数组中,assembly,Assembly,下面的代码假设对名为“array”的数组进行排序。然后忽略它所有的零,添加两个最低的数字,并将值存储到名为“parent”的新数组中。冒泡排序可以精确地对数组进行排序,但它并没有达到预期的效果。有人能帮我吗 ;huffman seperation lea dx,PROMPT_1 ;moving the address of PROMPT_1 message call display ;displays PROMPT_1 message
;huffman seperation
lea dx,PROMPT_1 ;moving the address of PROMPT_1 message
call display ;displays PROMPT_1 message
lea si,array ;moving the address of array in source index
call PRINT_ARRAY ;prints the whole array on screen
lea si,array ;moving the address of array in source index
call BUBBLE_SORT ;sorting algorithm to sort an array
lea dx, PROMPT_2 ;load and display the string PROMPT_2
call display
lea si, array ;set SI=offset address of ARRAY
lea di, parent ;loading an address of parent array in DI
call PRINT_ARRAY ;call the procedure PRINT_ARRAYT
mov ax, 0 ;used for moving address of array during addition
mov cx,512 ;512 times this calculation should be performed
lea si,array ;SI= pointer to array
huffloop:
calculation:
mov bx,[si] ;loading the address of array in bx
cmp bx,'0' ;if array has 0 value then jump to skipstep
jnz skipstep
condition:
add si+1,si ;if condition satisfies then add first two array contents
mov di,si+1 ;copying the resultant value to parent array too
mov [si],0 ;replacing the first lowest value in array to zero
lea dx,PROMPT_1 ;displaying the result on screen
call display
lea si,array
call PRINT_ARRAY
lea si,array
call BUBBLE_SORT ;doing bubble sorting again for repeating the step
LEA DX, PROMPT_2 ;load and display the string PROMPT_2
call display
lea SI, array ;set SI=offset address of ARRAY
call PRINT_ARRAY ;call the procedure PRINT_ARRAY
mov ax,0
skipstep:
add si,2 ;moving to next array address
jmp calculation ;jumping to calculation function
jnz huffloop ;jumping to huffloop
endofhuff:
除了您的代码无法汇编之外,还有一个逻辑错误:
calculation:
mov bx,[si] ;loading the address of array in bx
cmp bx,'0' ;if array has 0 value then jump to skipstep
jnz skipstep
condition:
...
skipstep:
jnz
错误。只要数据不是字符'0'
,就会执行到skipstep
的分支,因此循环只处理'0'
。测试应该是
cmp bx,'0' ;if array has 0 value then jump to skipstep
jz skipstep
您的条件和标签是否正确?您进行了
jmp计算
,然后立即执行jnz-huffloop
,但这两个标签标记了相同的位置,并且从未执行过这两个标签中的第二条指令。此外,标签条件:
从未跳转到。添加si+1,si
和mov di,si+1
这些是正确的说明吗?我是新装配的。也许我弄错了,它甚至不会组装,更不用说“不做它想做的事”。