x86 - 打印出由2个数组组成的qword数组?

时间:2017-10-31 03:27:13

标签: arrays assembly masm irvine32

我正在尝试将字符串的字符数组和DWORD数组放在一起,然后将它们反转为QWORD数组。因此,如果输入1,2,3,4,5和s,h,r,u,g,它将打印出g5 u4 r3 h2 s1。我一直只为一个数组获得奇怪的垃圾值。只有一个会像它应该打印。如果我将其中一个数组更改为另一个数组的副本,那么它的效果非常好。

include irvine32.inc

.data
string1 byte 0Ah,0Dh,"Dumping out charArr",0
string2 byte 0Ah,0Dh,"Dumping out numArr", 0
string3 byte 0Ah,0Dh,"Dumping out newArr", 0

charArr byte   5 dup  (?)
numArr  dword  5 dup  (?)
newArr  qword  5 dup  (?)

prompt1 byte "Please enter a number: ", 0
prompt2 byte "Please enter 5 characters: ", 0
prompt3 byte "The integer array you entered is: ", 0
prompt4 byte "The characters you entered are: ", 0
prompt5 byte "The mean of the integer array is: ", 0
prompt6 byte "The elements of the new array are: ", 0
prompt7 byte " ", 0

mov esi, offset numArr              ; number input
mov ecx, lengthof numArr
mov edx, offset prompt1
L1:
call writeString
call readDec
mov [esi], eax
add esi, type numArr
loop L1

mov esi, offset numArr              ; array output
mov ecx, lengthof numArr
mov edx, offset prompt3
call writeString
L3:
mov eax, [esi]
call writeDec
add esi, type numArr
mov al, ' '
call writeChar
loop L3
call crlf

mov esi, offset charArr             ; char input
mov ecx, lengthof charArr
mov edx, offset prompt2
call writeString
L2:
call readChar
mov [esi], al
add esi, type charArr
loop L2
call crlf

mov esi, offset charArr             ;char output
mov ecx, lengthof charArr
mov edx, offset prompt4
call writeString
L4:
mov eax, [esi]
call writeChar
add esi, type charArr
mov al, ' '
call writeChar
loop L4
call crlf

sub eax, eax                        
sub edx, edx
mov esi, offset numArr
mov ecx, lengthof numArr
L5:
add eax, [esi]
add esi, type numArr
loop L5
mov ecx, lengthof numArr
div ecx
mov ebx, edx
mov edx, offset prompt5
call writeString
call writeDec
call crlf


; reversing and combining arrays

mov esi, offset newArr                      
mov edi, offset charArr + type numArr       
mov ecx, lengthof newArr                    
mov edx, offset prompt6                     
call writeString                            
L6:                                         
    mov eax, [edi]                      
    dec edi                             
    mov [esi], eax                      
    add esi, type newArr            
    loop L6


mov esi, offset newArr + type numArr    
mov edi, offset numArr + type numArr * type numArr          
mov ecx, lengthof newArr                                
L7: 
mov eax, [edi]                  
sub edi, type numArr            
mov [esi], eax                  
add esi, type newArr            
loop L7


    ;printing
mov esi, offset newArr          
mov ecx, lengthof newArr        
mov edx, offset prompt7
L8: 
mov eax, [esi]                  
call writeChar                  
add esi, type numArr            
call writeDec
add esi, type numArr
call writeString
loop L8

0 个答案:

没有答案