我有一个用x86 MASM汇编语言编写的程序,它能够对数组进行排序。但是,我希望将其转换为一个过程,以便能够将其用于多个数组。你能帮我把这些代码转换成一个过程吗?另外,在这个过程中,你能告诉我如何将排序后的数组打印到黑屏上(这是我想要的功能,但由于我缺乏汇编语言知识而无法实现)。
INCLUDE Irvine32.inc
.data
arrayD dword 5,9,10,2,3
.code
main PROC
mov ebx, 5
OuterLoop: ; sorting the array in descending order
mov esi, offset arrayD
mov ecx, ebx
InnerLoop:
Lodsd
mov edx, [esi]
cmp eax, edx
jl Skip
mov [esi], eax
mov [esi-4], edx
Skip:
dec ecx
jnz InnerLoop
dec ebx
jnz OuterLoop发布于 2020-10-05 15:43:16
将该过程看作是一段可调用的代码(黑盒),其中包含有文档记录的输入、输出和功能。决定您的过程应该如何接受输入参数(调用约定),创建其文档,然后编写代码,并补充指令RET (这使其可调用)。如果代码中使用了PUSH和POP指令,请确保保持堆栈平衡。
BubbleSort: ; Procedure to sort an array of double-words.
; Input: EDI is pointer to the unsorted array of DWORDs.
; EBX is number of DWORDs in the input array.
; Output: The array is sorted in descending order.
; EAX,EBX,ECX,EDX,ESI are clobbered.
OuterLoop: ; sorting the array in descending order
mov esi,edi
mov ecx, ebx
InnerLoop:
Lodsd
mov edx, [esi]
cmp eax, edx
jl Skip
mov [esi], eax ; Swap neighbouring DWORDs.
mov [esi-4], edx
Skip:
dec ecx
jnz InnerLoop
dec ebx
jnz OuterLoop
RET 您的过程的典型调用:
mov edi, offset arrayD
mov ebx,5
CALL BubleSorthttps://stackoverflow.com/questions/64203321
复制相似问题