开发者

I Need Help Displaying a Value in Assembly [duplicate]

开发者 https://www.devze.com 2022-12-07 19:26 出处:网络
This question already has answers here: Displaying numbers with DOS (1 answer) How do I print an integer in Assembly Level Programming without printf from the c library?
This question already has answers here: Displaying numbers with DOS (1 answer) How do I print an integer in Assembly Level Programming without printf from the c library? (5 answers) Closed 4 hours ago.

I am pretty new to assembly and in need of some help. When working with single digit numbers, my code to display a value works fine. However, when it needs to work with bigger numbers it prints out answers that are not correct. When I work with testData1, testData2, testData3 and testData4, my program works as expected, however when it is switched with actualData, it does not print the correct value.

.model small ; one data segment, one code segment
.stack 100h ; reserves 256 bytes for the stack
.386 ; for 32 bit registers
.data ; start definition of variables
testData1  dd 1, -2, 3, 1 ;results in 3
testData2  dd 1, 1, 1 ;results in  3
testData3  dd 1, 1, -2 ;results in  0
testData4  dd -1, -2, -3 ;results in -6
;
actualData dd -14,  -9, -14, -12, 13,  2,
                7, -18,  10,  -8, 13, 12,
               11,  -1,   9,   3,  6, -1,
               11,  -9,  -6,  11, -3, 18,
               -7,  13, -11,  18, 10,  9,
               16,  11,  14, -19, 14, -3,

frequency dd 0
.code ; start code portion of program开发者_JS百科
main proc ; start of the main procedure
    mov  eax,@data ; load the address of the data segment into eax
    mov  ds,eax ; load the address of the data segment into ds
    mov  es,eax ;
    ; the three previous instructions initalize the data segment

cld
mov ebx, 0 ;temporary value
mov edx, 0 ;this will be the final register
mov ecx, 0 ;this will be my counter 
mov eax, 0 ;frequency
mov esi, 0 



mov esi, offset actualData
mov edi, lengthof actualData

firstloop:
cmp ecx, edi ;if statement for counter and lengthof
jge hopout
mov ebx, [esi + ecx*4]
add eax, ebx

mov ebx, 0
add ecx, 1
jmp firstloop ;jump

hopout:
rol ax, 8
mov dl, ah ; 
cmp dl, 10
jge hereJ
add dl,48 ;
jmp hereJ2
hereJ:
add dl, 55;
hereJ2:
mov ah,2
int 21h  ;

    
    mov  eax,4C00h ; 
    int  21h ; exit
main endp ; end procedure

end main ; end program

I tried switching things around and changing numbers for my code to display the value but I am stuck.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号