Программа сборки - Работа с отображением строк вместо регистров - PullRequest
1 голос
/ 19 июня 2020

Я написал этот код и мне нужен совет, почему он не отображает строковое сообщение для значений, а не для регистров?

Я пытался удалить je OutOfHere для самого большого l oop, но это приводит к ошибке программы. Если я закомментирую команду вместе с вызовом dumpreg, это вызовет ошибку.

Не знаю, что должно произойти, чтобы строка и значение отображались правильно. Заранее спасибо

TITLE SUM & AVERAGE & LARGEST w/ Print   (Program3.asm)

COMMENT !
3rd Program - Sum, Avg, Largest, w/ Print
CS340 Summer 2020
This program places an array of numbers to find the sum, avg, and largest
with the ASCII labels.
!

INCLUDE Irvine32.inc

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;; sum = eax,  avg = ebx,  remainder = ecx, largest = edx ;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


.data
ary          dword 50,-20,34,14,45,-37,82,134,83  ; Array to hold the required values
            dword 59,-24,1,-19,30,55,81,74,83,0
cnt         dword ?                       ; Count value holder
lrg          dword ?                              ; Largest value holder
reset        dword 0                          ; Reset value to avoid garbage
avg             dword 0                       ; Holder for the quotient 
rem         dword ?                       ; Remainder value holder
ans         byte  8 dup(?)                    ; Array for answer value
total          dword ?                        ; Total value of the array
NULL             equ   0                          ; Zero value holder
CR          equ   13                          ; Carriage Return
LF          equ   10                          ; Line Feed
labelSum        byte  "SUM = ", 0                 ; Displays Sum String
labelAvg        byte  "AVERAGE = ", 0             ; Displays Avg String
labelLrg        byte  "LARGEST = ", 0             ; Displays Large String
labelRem        byte  "REMAINDER = ", 0           ; Displays Remainder string


.code

WriteLine PROC
;Procedure writes the strings
    Top:
        mov     al, [esi]                   ; Move value of esi into AL 
        call    WriteChar                   ; MASM Function call 
        inc     esi                     ; Adds one to ESI for next value
        cmp     al, NULL                    ; Checks for the end of string
        jne     Top                     ; Jump to Top if not equal
    ret 
WriteLine ENDP

WriteNum PROC
;Procedure writes the interger values

        dec     esi                     ; Takes one away from ESI
    Top:
        mov         al, [esi]                   ; Moves ESI value into AL
        call    WriteChar                   ; MASM function call to write char
        dec     esi                     ; Reduces ESI by one
        cmp       al, NULL                  ; Check for end of values
        jne     Top                     ; If not equal repeat loop
    ret 
WriteNum ENDP

IntToAsc PROC
;Procedure converts ints to ascii
        mov     ebx, 10                 ; Places value 10 into EBX
    Top:
        mov         edx, NULL                   ; Places 0 into EDX
        cwd                             ; Convert to Double Word
        idiv      ebx                       ; Divides EAX with EBX
        add     dl, 30h                 ; Adds 30h to DL
        mov     [esi], dl                   ; Moves DL into ESI 
        inc     esi                     ; Adds 1 to ESI for next value
        cmp       eax,NULL                  ; Checking for end of values
        jne         Top                     ; If not equal jump to top
    ret
IntToAsc ENDP   

NextLine PROC
;Procedure to create the next line
        mov     eax, CR                 ; Move CR into EAX
        call         WriteChar                   ; MASM function call
        mov     eax, LF                 ; Move LF into EAX
        call        WriteChar                   ; MASM function call
    ret
NextLine ENDP

main PROC

   ;Clearing the Registries 
        mov     eax, reset              ; Clears the registry and places 0 into memory
        mov     ebx, reset              ; Clears the registry and places 0 into memory
        mov     ecx, reset              ; Clears the registry and places 0 into memory
        mov     edx, reset              ; Clears the registry and places 0 into memory

   ;Start of the program
        mov     esi, offset ary         ; Places the address of ary into esi

    Sum:                 ; Loop for Sum
        add     eax, [esi]              ; Adds the array value of esi into eax
        inc     cnt                     ; Adds one to count
        add     esi, 4                  ; Bump pointer to retreive next number
        cmp     edx, [esi]              ; Compare value of esi to edx
        jne     Sum                     ; Jump back to sum if edx and esi are unequal

        mov     ecx, eax                     ; Moves eax(total) into ecx(remainder)
        inc     ecx                     ; Forced inc for remainder to be correct
        inc     eax                     ; Forced inc for total to be correct

    Average:                                      ; Loop for Average
        sub     ecx, cnt                    ; Subtract count from ecx
        inc     ebx                     ; Adds one to ebx 
        cmp      ecx, cnt                    ; Compares count to the value of ecx
        ja      Average                 ; Jump to Avg if value is greater than 

        mov     esi, reset              ; Reset the esi register to 0
        mov     esi, offset ary         ; Place the array address into esi
        mov     edx, [esi]              ; Move first value of esi into edx
        mov     lrg, edx                     ; Move edx into lrg
        mov     rem, ecx                     ; Move ecx into rem
        mov     ecx, reset              ; Reset ecx
        mov     edx, [esi]              ; Places an esi value into edx
        mov     avg, ebx                     ; Move ebx into quotient 

    Largest:                                ; Loop for Largest
        cmp     edx, [esi]              ; Compares esi and edx 
        jl       Temp                       ; Jump to temp if edx is less than esi
        add      esi, 4                 ; Bump to the next number in esi
        cmp     [esi],ecx                   ; Compares ecx to esi
        je      OutOfHere               ; Jump if equal to end program
        jne     Largest                 ; Jump to top if unequal

    Temp:                               ; Loop for temp largest value 
        mov     edx, [esi]              ; Move next value of esi into edx
        mov     lrg, edx                    ; Move edx into large
        cmp     edx, 0                  ; Compare to ensure it's not last value
        mov     ecx, rem                    ; Move remainder back into ecx
        jmp     Largest                 ; Jump to back to largest 

    ; Prints value and string for sum
        lea     esi, labelSum               ; Moves the label into ESI
        call      WriteLine                 ; Calls WriteLine function
        mov       eax, total                ; Move total into eax
        lea     esi, ans                    ; Move answer of the array 
                                        ; into esi
        call      IntToAsc                  ; Function call 
        call      WriteNum                  ; Function call 
        call    NextLine                    ; Function call

    ; Prints value and string for average
        lea     esi, labelAvg               ; Moves the label into ESI
        call      WriteLine                 ; Calls WriteLine function
        mov       eax, avg                  ; Move total into eax
        lea     esi, ans                    ; Move answer of the array 
                                        ; into esi
        call      IntToAsc                  ; Function call 
        call      WriteNum                  ; Function call 
        call    NextLine                    ; Function call

    ; Prints value and string for remainder
        lea     esi, labelRem               ; Moves the label into ESI
        call      WriteLine                 ; Calls WriteLine function
        mov       eax, ecx                  ; Move ecx into eax
        lea     esi, ans                    ; Move answer of the array 
                                        ; into esi
        call      IntToAsc                  ; Function call 
        call      WriteNum                  ; Function call 
        call    NextLine                    ; Function call

    ; Prints value and string for largest
        lea     esi, labelLrg           ; Moves the label into ESI
        call      WriteLine             ; Calls WriteLine function
        mov       eax, lrg              ; Moves largest into eax
        lea     esi, ans                ; Move answer of the array 
                                    ; into esi
        call      IntToAsc              ; Function call 
        call      WriteNum              ; Function call 
        call    NextLine                ; Function call

        OutOfHere:
        call    DumpRegs                ; display the registers

    exit
main ENDP
END main

1 Ответ

0 голосов
/ 22 июня 2020

IntToAs c PRO C должен начинаться с записи нуля по адресу в ESI, чтобы WriteNum PRO C имел возможность обнаружить, что NULL!

Оба WriteLine и writeNum PROC должны загрузить байт по адресу ESI перед проверкой нуля !

WriteLine PROC
;Procedure writes the strings
    Top:
        mov     al, [esi]                   ; Move value of esi into AL 
        call    WriteChar                   ; MASM Function call 
        inc     esi                     ; Adds one to ESI for next value

        MOV AL, [ESI]    <<<<<<<<<

        cmp     al, NULL                    ; Checks for the end of string
        jne     Top                     ; Jump to Top if not equal
    ret 
WriteLine ENDP

WriteNum PROC
;Procedure writes the interger values

        dec     esi                     ; Takes one away from ESI
    Top:
        mov         al, [esi]                   ; Moves ESI value into AL
        call    WriteChar                   ; MASM function call to write char
        dec     esi                     ; Reduces ESI by one

        MOV AL, [ESI]    <<<<<<<<<

        cmp       al, NULL                  ; Check for end of values
        jne     Top                     ; If not equal repeat loop
    ret 
WriteNum ENDP
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...