I'm a newbie to this forum, and I need a little bit of assistance.

i'm having trouble writing a proggie (apparently)

i have to write a program that reads 16 numbers (range from 0-999) from the standard input and displays them on the screen as a 4 X 4 matrix. Like this:

0 50 2 200
66 21 54 20
1 3 4 6
100 150 120 99

then, it has to:
1) compute and display the sum of row 1
2) compute and display the sum of col 2
3) count and display the number of values > 100
4) wait for a key to be pressed, and then interchange rows 1 and 2 and redisplay the matrix.

this is what i have. anyone have any advice?


Title Assignment6 (try2.asm)

.model small
.stack 100h

.data
numberPrompt db "Enter a number between 0 and 999: ", 0
sumRow1Msg db "The sum of row 1 is: ", 0
sumCol2Msg db "The sum of column 2 is: ", 0
numGtr100Msg db "The number of values > 100 is: ", 0
notInRangePrompt db "The value in not in the range: ", 0
matrix dw 16 dup (?)
count = 16

.code
extrn Writestring:proc, Readint:proc, Writeint:proc, Crlf:proc

main proc
mov ax, @data
mov ds, ax

call GetNums
call DisplayMatrix
call sumRow1
call sumCol2
call Greater100
call Swap1W2

main endp

GetNums proc
push cx
; mov es, @data
mov di, offset matrix
mov cx, count

GetData:
mov dx, offset numberPrompt
call Writestring
call Readint

;if (ax > 999) or (ax < 0) then jump to NOTINRANGE else jump to INRANGE

cmp ax, 999
jg NOTINRANGE
cmp ax, 0
jl NOTINRANGE
jmp INRANGE

NOTINRANGE:
mov dx, offset notInRangePrompt
dec cx
loop GetData

INRANGE:
call Crlf
stosw ; stosw = es:[di]=ax; di+=2
loop GetData

pop cx
GetNums endp


DisplayMatrix proc
mov si, offset matrix
mov cx, count
Display:
lodsw ;(equivalent to mov ax,ds:[si]; add si,2)
mov bx,10
push cx ; (make sure WriteInt does not modify it)
call WriteInt
pop cx
dec cx ;(decrease cx by one, and check if lowest 2 bits are zero,
;which means 4*k items have been printed, where k is integer)
test cx,3
jnz short NotEndOfLine
push cx
call Crlf
pop cx
NotEndOfLine:
or cx,cx ;(if cx is not zero jump back to Display)
jnz Display
DisplayMatrix endp

;get sum row 1
sumRow1 proc
mov si, offset matrix
mov bx, [si]
mov cx, 3
Sum1:
add si, 2
add bx, [si]
loop Sum1

mov dx,offset sumRow1Msg
push bx
call Writestring
pop bx

mov ax,bx ; get the sum(in BX)
mov bx,10
call Writeint ; display it
call Crlf
sumRow1 endp

;get sum col 2
sumCol2 proc
mov si, offset matrix+2
mov bx, [si]
mov cx, 3
Sum2:
add si, 8
add bx, [si]
loop Sum2

mov dx, offset sumCol2Msg
push bx
call Writestring
pop bx
mov ax,bx ; get the sum(in BX)
mov bx,10
call Writeint ; display it
call Crlf
sumCol2 endp

; count display number vals > 100
;while (cx < count)
;{
; if ([si] < 100)
; count = count + 1
; cx++
; si = si +2
;}
Greater100 proc
mov si, offset matrix
xor bx, bx ; set bx to zero

mov cx, 1
While:
cmp cx, count
jg Enddo
cmp [si], 100
jl L2
inc bx
L2:
inc cx
add si, 2
jmp While
Enddo:
mov dx, offset numGtr100Msg
push bx
call Writestring
pop bx
mov ax,bx ; get the sum(in BX)
mov bx,10
call Writeint ; display it
call Crlf
Greater100 endp

;swap rows 1 and 2
Swap1W2 proc
mov si, offset matrix
mov di, offset matrix+8
mov cx, 4
rowSwap:
mov bx, [si]
xchg bx, [di]
mov [si], bx
add si, 2
add di, 2
loop rowSwap
call DisplayMatrix
Swap1W2 endp

end main
Posted on 2002-04-24 02:50:44 by Zombiefreak
Howdy Zombiefreak,

This looks like a school assignment. Which means figuring it out on your own is a major point of the exercise. Furthermore, I'm probably the last person on the forum to have helpful assembly advice--I'm as new if not newer to assembly than you. So, this post isn't going to have the answer you thought you were looking for.

However, some thoughts you may not have realized you needed:

- You can paste code and preserve formatting by using the [code] and code] tags (note: use square braces, not curly).
- Try telling us what your program does wrong. Does it add incorrectly? What output DOES it generate? Does it crash when you type input? What kind of crash, and what error messages? Does it not assemble? What error messages does the assembler emit?
- I'm not trying to put you off; rather I'm trying to help you see how to formulate a question that will elicit answers. :)

Good luck!

-Chalain

Posted on 2002-04-24 11:59:49 by Chalain
Well, i'm getting an error that says:
assembly1 <129> : fatal error A1008 unmatched marco nesting

i've got most of the math worked out pretty well, to where it should work. however, i'm not good with outputing to the screen. I don't know how to output the matrix to the screen, in a right justified form. Any tips?

i'm trying to go through my old assignments to figure out what i did wrong. my prof's kinda difficult and doesn't assist very much.
Posted on 2002-04-24 12:04:41 by Zombiefreak

i'm trying to go through my old assignments to figure out what i did wrong. my prof's kinda difficult and doesn't assist very much.
What about your class buddies? I always worked in groups - mainly so we could pick each other up when we were falling down drunk. :)
Posted on 2002-04-24 12:08:23 by bitRAKE
Okay, again, I'm the worst assembly guy here, but...

The error code is on the last line of the program, which usually means SHGHW (Something Has Gone Horribly Wrong), which also usually means you've got a formatting, layout, or pairing error somewhere. You're probably omitting something early on in your code, like a close tag for something you opened.

Hmm... Or, an open tag for something you've closed! I don't have a 16-bit assembler, but I see what would be a bug on my system:

Your program ends with end main, but your .code segment does not begin with

main:


Could that be it?

OH, also... none of your procs end with ret. Is that intentional?

Cheers!

-Chalain
Posted on 2002-04-24 12:17:19 by Chalain
Chalain, if you got masm you actually *do* have a 16bit assembler...
you might not have a 16bit linker tho ;)
Posted on 2002-04-24 12:31:25 by f0dder

Chalain, if you got masm you actually *do* have a 16bit assembler...
you might not have a 16bit linker tho ;)


D'OH! That's right.

Hey, I *said* I was a poor authority. :tongue:

...at least I was right about that. :grin:

-Chalain
Posted on 2002-04-24 15:52:44 by Chalain



Hmm... Or, an open tag for something you've closed! I don't have a 16-bit assembler, but I see what would be a bug on my system:

Your program ends with end main, but your .code segment does not begin with

main:


Could that be it?

OH, also... none of your procs end with ret. Is that intentional?


I just looked this over again, to make sure it wasn't a script kiddie screw up, but it's not...whew. From what I know (and what I've read in our book), code needs to look something like:


main proc
blah blah blah
call someFunction
main endp

someFunction
blah blah blah
someFunction endp

end main

that's it.

i've made a lot of corrections to the code to where it SHOULD work properly, but I'm still getting the unmatched macro nesting error.

Edited code above as well.

I found a standard library that'll format the matrix and all, but i'm tryin' really hard to figure all this stuff out. can anyone help with that error?
Posted on 2002-04-24 17:59:45 by Zombiefreak
Try renaming the label While to something else. It's potentially confusing to the assembler to use a predefined identifier (while is actually a macro loop directive) as a label.
Posted on 2002-04-26 14:59:45 by tenkey