GIDForums  

Go Back   GIDForums > Computer Programming Forums > Assembly Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 20-Dec-2007, 06:44
randomperson133 randomperson133 is offline
New Member
 
Join Date: Dec 2007
Posts: 4
randomperson133 is on a distinguished road

Two bugs in my program that just won't go away.


The two bugs in my code that won't go away are the following:

1) I cannot get proc charbychar to print out whatever's in myname: It only prints out the $ at the end of the string.

2) Findmax always returns 0 as the largest value in the array regardless of what input I used for nums.

If anyone can help me spot what's wrong then I'd really appreciate the help. Below is the code for the main program and the external proc printmsg:

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
  #2  
Old 23-Mar-2008, 07:04
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 405
Peter_APIIT is on a distinguished road

Re: Two bugs in my program that just won't go away.


Did u using 02h function to print char by char ?
__________________
Linux is the best OS in the world.
 
 

Recent GIDBlog2nd Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Two-Tier data dissemination code installation problem nidhibansal1984 Computer Software Forum - Linux 6 16-Sep-2007 10:13
BOOKEEPING program, HELP!! yabud C Programming Language 10 17-Nov-2006 03:48
Pipeline freeze simulation darklightred CPP / C++ Forum 6 27-Jul-2006 19:37
How to read particular memory location ? realnapster C Programming Language 10 10-May-2006 09:11
Type casts ? kai85 CPP / C++ Forum 12 23-Jun-2005 12:04

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 23:31.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.