×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

help w/ 4x4 matrix

help w/ 4x4 matrix

help w/ 4x4 matrix

(OP)
i'm having trouble writing a proggie.  can anyone assist?

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.

RE: help w/ 4x4 matrix

(OP)
here's the code i have so far:

.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
    matrix db 4 dup (?)
           db 4 dup (?)
           db 4 dup (?)
           db 4 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
    mov si, offset matrix
    mov cx, count
    GetData:
        mov dx, offset numberPrompt
        call Writestring
        call Readint
        call Crlf
        mov [si], ax
        add si, 2
        loop GetData
GetNums endp

DisplayMatrix proc
    mov si, offset matrix
    mov cx, 4
    loop:
        mov ax, [si]
        mov bx, 10
        call Writeint
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
    call Writestring
    mov  ax,bx             ; get the sum(in BX)
    mov  bx,10
    call Writeint      ; display it

sumRow1 endp

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

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

; count display number vals > 100
;while (cx < count)
;{
;    if ([si] < 100)
;         count = count + 1
;    cx++
;    si = si +2
;}
Greater100 proc
    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
        call Writestring
        mov  ax,bx             ; get the sum(in BX)
        mov  bx,10
        call Writeint      ; display it
Greater100 endp

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

end main

RE: help w/ 4x4 matrix

Hmm,

        call Writestring
        call Readint
        call Crlf
        mov [si], ax


How sure are you that the Crlf routine will NOT trash the contents of ax?

    call sumCol2
    call Greater100
    call Swap1W2

After this.... you're not going to do a DisplayMatrix?  Swap1W2 isn't going to display the matrix...


"Information has a tendency to be free.  Which means someone will always tell you something you don't want to know."

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close