简体   繁体   English

计算数组中数字之间的差异(Assembly,Irvine)

[英]Calculating different between numbers in array(Assembly, Irvine)

I'm trying to calculate the gaps between the numbers.我正在尝试计算数字之间的差距。 For that purpose I'm using 2 arrays.为此,我使用了 2 个数组。 So everything works fine except output and strange symbols that appears after the numbers.所以除了输出和数字后面出现的奇怪符号外,一切正常。

first number-number in array at this moment, 2nd-different between elements, 3d- 2nd that already moved to the second array.此时数组中的第一个数字,元素之间的第 2 个不同,第 3-2 个已经移动到第二个数组。 Output: 1 2 2 /3 44/722/9one/输出:1 2 2 /3 44/722/9one/
2 2

From where this symbols?这个符号从哪里来? What cause it?是什么原因造成的? Wrong register?注册错误? And why in the first loop 'gap'(array) has right numbers,but when I go through this array later it has just 2 and wired symbol?为什么在第一个循环中 'gap'(array) 有正确的数字,但是当我稍后通过这个数组时它只有 2 和有线符号?

INCLUDE Irvine32.inc

.data
array byte 1,3,7,9
gap byte ?
blank byte ' '
ph byte "Done",0

.code
main PROC
        mov eax,0
        mov ecx,lengthof array  
        mov esi, offset array
        mov edi,offset gap
         arr:

         mov al,[esi]
         call writedec; here

         .if ecx==1
         mov edx,offset ph 
         call writestring
         .else
         mov al,blank
         call writechar

            mov al,[esi+1]
            sub al,[esi]

            call writedec; here

            mov [edi],al

            ;check block
            mov al,blank
            call writechar
            mov al,[edi] ; here
            call writedec
            mov al,blank
            call writechar

             inc esi
             inc edi        
           .endif

           mov al,'/'
         call writechar

         loop arr

        call crlf  

         mov eax,0
         mov ecx,lengthof gap
         mov esi,offset gap

         go:

         mov al,[esi]
         call writedec
         mov al,blank
         call writechar
         inc esi
         loop go

         exit

main ENDP



myexit proc

              call waitmsg
              ret
      myexit endp

end main

Thank you!谢谢!

Gotcha!知道了! the variable gap was wrong initialize.变量间隙初始化错误。

This is the right initialization gap byte lengthof array-1 dup(?)这是正确的初始化gap byte lengthof array-1 dup(?)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM