Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Two Problems with my code

Status
Not open for further replies.

randomperson1337

Programmer
Dec 19, 2007
1
There are two bugs in my code that simply won't go away no matter how much I try to fix them, and they are:

1) When I use charbychar to print out string 'myname', all I get is '$'.
2) Findmax returns 0 in ax no matter what values I had input into the array nums earlier on.

Any input on this issue is deeply appreciated.

Code:
        .model          small
        .stack          100h
        .data
msg1    db              "Program start", 13, 10, "$"
nuln    db              13, 10, "$"
ttle    db              "This program demonstrates the manipulation of arrays in 8086 Assembler.", 13, 10, "$"
count   dw              ?
myname  db              14 DUP (?)
nums    dw              16 DUP (?)
prmt0   db              "Enter name: $"
prmt1   db              "Input number of ints to read in (1 to 15): $"
prmt2   db              "Enter an integer: $"
oa      db              "Original Array", 13, 10, "$"
sa      db              "is the sum of the array elements.", 13, 10, "$"
ua      db              "Updated Array", 13, 10, "$"
la      db              "is the largest input value.", 13, 10, "$"
fin     db              "Finished.", 13, 10, "$"
	.code
extrn     printdec:     proc
extrn     getdec:       proc
extrn     printmsg:     proc
Assn6     proc

        mov     ax, @data
        mov     ds, ax

        mov     dx, offset ttle
        mov     ah, 09h
        int     21h

        mov     dx, offset prmt0
        mov     ah, 09h
        int     21h

        ;Read in a name into myname via character I/O. Put in a '$' at the end of the char array.
        sub     si, si
        mov     ah, 01h
Top:    int     21h
        mov     myname[si], al
        inc     si
        cmp     al, 13
        jne     Top
        mov     myname[si], '$'

        mov     dx, offset nuln
        mov     ah, 09h
        int     21h

        ;Read in how many integers to read into nums, then read in that many. (15 maximum)

Tap:    ;Prompt for number of ints to read into num.
        mov     bx, offset prmt1
        call    printmsg

        call    getdec

        cmp     ax, 0
        jle     Btm

        cmp     ax, 15
Btm:    jg      Tap

        mov     cx, ax
        mov     count, ax

        sub     si, si
R3p:    ;Prompt for value to store in array slot.
        mov     bx, offset prmt2
        call    printmsg

        call    getdec
        mov     nums[si], ax
        add     si, 2
        loop    R3p

        ;Call printmsg to print string myname via function 9 of int 21h.
        mov     bx, offset myname
        call    printmsg

        ;Send myname to charbychar and print that out character by character, '$' included.
        mov     bx, offset myname
        call    charbychar

        ;Print a heading like "Original Array"
        mov     bx, offset oa
        call    printmsg

        ;Send nums to printarray and use that to print its values.
        mov     bx, offset nums
        mov     cx, count
        call    printarr

        ;Use sumarray to sum up the n values in nums.
        call    sumarr
        call    printdec

        mov     bx, offset sa
        call    printmsg

        ;Print a heading like "Updated Array"
        mov     bx, offset ua
        call    printmsg

        ;Use add12 to deal with the +12 to each negative value in nums then call printarr to display the updated values.
        mov     bx, offset nums
        call    add12

        call    printarr

        ;Use findmax to find largest value in nums array.
        mov     bx, offset nums
        call    findmax
        call    printdec

        mov     bx, offset la
        call    printmsg

        mov     ah, 4ch           ;Return to DOS
        mov     al, 0
        int     21h

Assn6    endp

;Prints out an array character by character.
charbychar  proc
        push    ax
        push    si

        sub     si, si
        mov     ah, 02h
Top1:   mov     dl, [bx + si]
        int     21h
        cmp     dl, '$'
        je      Done
        inc     si
        jmp     Top1
Done:

        pop     si
        pop     ax
        ret
charbychar endp

;Displays the contents of array nums.
printarr  proc
        push    ax
        push    bx
        push    cx

        sub     si, si
Top2:   mov     ax, [bx + si]
        call    printdec
        add     si, 2
        loop    Top2

        pop     cx
        pop     bx
        pop     ax
        ret
printarr  endp

;Computes the summation of the array's values and returns that to main for printing via printmsg.
sumarr    proc
        push    cx
        push    si

        sub     ax, ax
        sub     si, si
Top3:   add     ax, [bx + si]
        add     si, 2
        loop    Top3

        pop     si
        pop     cx
        ret
sumarr    endp

;Searches through the array's elements and adds 12 to each one that is negative.
add12     proc
        push    ax
        push    cx
        push    si

        sub     si, si
Top4:
        cmp     [bx + si], 0
        jge     Pos
        add     [bx + si], 12
Pos:    add     si, 2
        loop    Top4

        pop     si
        pop     cx
        pop     ax
        ret
add12     endp

;Finds the largest value in the array and returns that to main.
findmax   proc
        push    cx
        push    si

        sub     si, si
        sub     ax, ax
Top5:   cmp     ax, [bx + si]
        jl      Lstn
        mov     ax, [bx + si]
Lstn:   add     si, 2
        loop    Top5

        pop     si
        pop     cx
        ret
findmax   endp
          end     Assn6


;Code for external proc printmsg

        .model          small
        .data
nuln    db              13, 10, "$"
	.code
PUBLIC    printmsg
printmsg    proc

        push    ax
        push    dx

        mov     dx, bx
        mov     ah, 09h
        int     21h

        mov     dx, offset nuln
        mov     ah, 09h
        int     21h

        pop     dx
        pop     ax

        ret

printmsg    endp
          end
 
i hope i could help you on your code but i need some explanation abolut what you need if you could and by the
way will read your code all and try to help

 
i think you have a problem in this part of your code


Top: int 21h
mov myname[si], al
inc si

; here i think you should compare si with 13 and not al
;because here the si is incremented and as i saw in the
;data segment that you reserve only 14 place for
;" myname " i think that you will enter a name;;;;;;;; from ;keybord because you make here an interrupt so the ;code will be
; cmp si ,13
; and if it reach 13 so put the sign dollar
cmp al, 13

jne Top
mov myname[si], '$'

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top