News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Reduced Row-Echelon Form of a Matrix Help

Started by brettc431, April 18, 2013, 12:35:02 AM

Previous topic - Next topic

dedndave

you're probably right, Michael
although, i remember writing some parsing loops that used the count
i also used LODSB and LOOP, so don't let Hutch see this post - lol
;DS = PSP segment

        mov     si,80h        ;PSPTailLen
        lodsb                 ;SI now points to the tail
        cbw
        xchg    ax,cx

loop00: lodsb
;
;parsing code
;
        loop    loop00

FORTRANS

Hi Dave,

   In my code I have a check for a command tail.  The ES segment
register points to the PSP on program load.  And the carriage
return that terminates the command line is not part of the count.

        MOV     BL,ES:[80H]     ; Length of cmd tail
        XOR     BH,BH           ; Length byte -> word
        XOR     CX,CX           ; Zero tail length
        CMP     BL,1            ; must be non-zero
        JB      FN2_3


   Just a quick and easy sanity check.

Hi Michael,

   If you want to allocate memory, you can skip the deallocation
steps if you use a linker option to limit the memory allocated to
the program when it is loaded.  Oh, that seems very version
dependent.  Just checked to see the spelling, and some versions
don't support it.  Anyway, if supported, the /CPARMAXALLOC or /CP:
option will limit the memory allocated to a program.  /CP:1 will
let the linker limit the program's memory to only what it needs
to load properly.  Then you can allocate memory as you mentioned.
Just a short cut.

Regards,

Steve N.

brettc431

This is my final code before we have to test it today and show our instructor that it works.  I don't have matlab on my laptop so I'm going to post it up here for anyone to look at if they want.  Just want to know if there are any errors I haven't corrected before we get into the lab today.  Thanks again for all your help everyone.


.MODEL SMALL ;Defines memory model as small which uses separate segments for code and data
.386 ;Microprocessor number
.STACK ;Stack segment defined as 1024 by default
.DATA ;Begins definition of the data type used in this project

mrc DD ?
scale DD ?
D DD ?
row DB ?
col DB ?
e DD ?
ep1 DD ?
M DD 10000 DUP(?)
INPUT DB "input", 0
OUTPUT DB "output", 0
IHANDLE DW ?
OHANDLE DW ?



;-------------------------------------------------------------------------------------
;calcoffset takes two input variables and calculates the equation: (op2-1)*op1+(op1-1)
;The value is returned into M[EAX]
;-------------------------------------------------------------------------------------
calcoffset MACRO op1, op2 
PUSH ESI
PUSH EDI
MOV ESI, op1
MOV EDI, op2
DEC EDI
MUL EDI
ADD EAX, ESI
DEC EAX ;M[EAX]
POP EDI
POP ESI
ENDM
;------------------------------------------------------------------------------------

.CODE
MAIN PROC FAR
.STARTUP
;Program:

PUSHAD
MOV EAX, 0h
MOV AH, 62h
INT 21H
MOV ES, BX

MOV SI, 81h
CMP BYTE PTR ES: [SI-1], 1
JBE NO_TAIL

MOVZX ECX, BYTE PTR ES:[SI-1]
L0: MOV DL, ES:[SI]
INT 21H
INC SI
LOOP L0

NO_TAIL: MOV DL, 0Ah
INT 21H
MOV DL, 0Dh
INT 21H



MOV BP, 0
MOV SI, 0

MOV AX, 3D00h ;Open input file
MOV DX, OFFSET INPUT
INT 21H
MOV IHANDLE, AX

MOV AX, 3D01h ;Open output file
MOV DX, OFFSET OUTPUT
INT 21H
MOV OHANDLE, AX

MOV BX, IHANDLE
MOV CX,2    ;Want to read two bytes.
MOV DX, OFFSET D
MOV AH, 3FH ;Read
INT 21H
JC  QUIT
    CMP AX,2
       
       
        MOV CX,8    ;Want to read eight bytes.
MOV DX, OFFSET M
MOV AH, 3FH ;Read
INT 21H
JC  QUIT
    CMP AX, 8
JNE QUIT

MOV ESI, 1
MOV EDI, 1
MOVZX EAX, row



MOV ECX, ESI
MOV EBP, 1
DEC ECX
L1:
calcoffset EBP, EBP
MOV EDX, M[EAX]
MOV e, EDX
INC ESI
MOV ESI, EBP
MOV EDI, EBP
calcoffset ESI, EBP
MOV EDX, M[EAX]
MOV ep1, EDX

;calc scale to fpu
FINIT
FLD e
FLD ep1
FDIV
FST scale
JMP L2

RETURN: JMP L1

L2:
calcoffset ESI, EDI
MOV EDX, M[EAX]
MOV mrc, EDX

;fpu to calc mrc*scale+e
FINIT
FLD mrc
FLD scale
FMUL
FCHS
FLD e
FADD
FST mrc

INC EDI
MOVZX EDX, col
CMP EDI, EDX
JBE L2
INC ESI
MOVZX EDX, row
CMP ESI, EDX
JBE L2
JMP RETURN

     
        MOV AH, 40h
MOV BX, OHANDLE
MOV CX, LENGTHOF M
MOV DX, OFFSET OUTPUT
INT 21H


MOV AH, 3Eh
MOV BX, IHANDLE
INT 21H
        MOV BX, OHANDLE
        INT 21H
       
       
QUIT:  .EXIT
MAIN    ENDP
      END

dedndave

right - as i said before, the DS and ES registers point to the PSP at start-up
so, before i set the DS register, i would set the ES register to the local data segment
DS is still pointing to the PSP
so LODSB gets a byte from the command line tail and STOSB stores it in the data segment "parsed buffer"

dedndave

Brett...

at the end of the program source....
        END     MAIN

the END directive should reference the entry point

brettc431

I always miss little obvious things when it comes to code, thanks  :t