News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Linking programs

Started by veronicak5678, October 09, 2009, 02:33:44 AM

Previous topic - Next topic

dedndave

it's all good - lol
we can use multiple code and data segments
i got a 4-digit random number as output (different each time), then it displays several garbage characters and hangs
do you have the source file for the procedures in io.lib so i can take a look at them ?

veronicak5678

Sorry, I'm not sure what you mean...

Our teacher had us download a file that had that library in it, but I don't see anything like source files for the procedures.

Also, as a check to see if it is working when the seed is 555H, the first few numbers should be 832, 6809, 8658, and 1206.

dedndave

can you give me the link for the download ?
i need to see how to use those procedures
or - i'll just write my own - lol

dedndave

here is what i have so far
you can see that i modified the asm files
and, i made a batch file to assemble them - look inside that to see the command lines

veronicak5678

It was just a folder he put on a drive at school. I think I found what you wanted though.

veronicak5678

#35
        JGE     HIGH_SEQUENCE       ;a count below 5000 gets counted as both high and low ?

        INC     LOWCOUNT

HIGH_SEQUENCE:


I thought this would skip over 'inc lowcount' if greater or equal than 5000 and go to highsequence? Same here:

        JNE     ODDS                ;an even value gets counted as both even and odd ?

        INC     EVENCOUNT

ODDS:
        INC     ODDCOUNT



PBrennick

If the value is less than 5000, both LOWCOUNT and HIGHCOUNT get incremented. Is this what you want? also,


   PUSH LOWER
   PUSH UPPER


These two line are never popped which is why you need the RET 4. Remove those two lines and you will only need RET. This is not your problem, though, just not good coding (we spoke of this before or was it a comment I made to FORTRAN). Another way you could clean that up is to add UPPER and LOWER to the proc statement so the procedure will do the popping for you. If either option is used RET 4 must be changed to RET for stack balancing.


   CMP BL,0
   JNE NOTZERO


I assume BL should contain the value of the seed? If so, that code is missing.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

veronicak5678

No, I want highcount incremented if it is 5000 or above and lowcount to be incremented if it is under. I was told a jump like jge would jump past whatever is between it and the place it is jumping to, so JGE     HIGH_SEQUENCE  would skip past         INC     LOWCOUNT and go to HIGH_SEQUENCE. If that is incorrect, please tell me how to increment low and high.

BL should not contain the value of the seed. BL should contain either a 1 or a 0. This is set in main. First, it will set BL = 0 and call reseed, which will cause reseed to call random and use that for a seed. Then main will call random 100 times and print out the values and get stats. Then main will set BL = 1, which will cause reseed to set the seed = 555H. Then main goes into a loop again and prints and collects data. When those two loops are over, main will print out the statistics for high/low and even/odd for all 200 numbers.

FORTRANS

Hi,

   You have:


           CMP     DX, 0
           JNE     ODDS
           INC     EVENCOUNT
ODDS:
           INC     ODDCOUNT


and that counts even numbers if not odd, but counts
odd numbers all the time.

You will want something more like:


           CMP     DX, 0
           JNE     ODDS
           INC     EVENCOUNT
           JMP     EVENS   ; If even, don't count odds.
ODDS:
           INC     ODDCOUNT
EVENS:


Steve

veronicak5678

Oh! I see. Here's the new one. Now sometimes i get numbers, sometimes I get errors, and sometimes I get 'divide overflow.' When main calls reseed, will it continue through reseed all the way to random? Or will it return to main with the ret in reseed?

;===================================================================
;                   RANDOM.ASM
;      r a n d o m   n u m b e r   g e n e r a t o r
;
; GENERATES PSEUDO-RANDOM INTEGERS IN THE RANGE LOWER TO UPPER
; INPUT:  TWO STACK PARAMETERS - LOWER AND UPPER ENDS OF RANGE
; OUTPUT: AX-REG CONTAINS RANDOM INTEGER
; CALLING SEQUENCE:     PUSH    <LOWER END OF RANGE>
;                       PUSH    <UPPER END OF RANGE>
;                       CALL    RANDOM
;===================================================================
           .MODEL  SMALL, BASIC
   .586
           .STACK 256
;===================================================================
; D A T A   S E G M E N T   D E F I N I T I O N
           .FARDATA RAND_DATA
SEED       DW      ?                   ;SEED FOR RANDOM NUMBER GEN.
MULTIPLIER DW      25173               ;MULTIPLIER AND
ADDEND     DW      13849               ;ADDEND FOR MIXED
                                       ;LINEAR CONGRUENTIAL METHOD
UPPER    DW      9999
LOWER      DW      0
PUBLIC SEED
;===================================================================
; C O D E   S E G M E N T   D E F I N I T I O N
           .CODE   
RESEED PROC PUBLIC
   MOV  AX, RAND_DATA
   MOV  DS, AX
           ASSUME DS:RAND_DATA     
           PUSHF                   
           CMP BL,0
           JNE NOTZERO
           PUSH LOWER
           PUSH UPPER
           CALL RANDOM
           MOV  SEED, AX
           JMP ZERO
NOTZERO:
           MOV SEED,555H
ZERO:
           POPF                       
           RET  4                   
RESEED     ENDP                     


RANDOM   PROC NEAR PUBLIC USES CX DX DS

MOV   AX,RAND_DATA
MOV DS, AX


           PUSHF                       
           MOV     AH,0                ;     SEED = LOWER HALF OF
           INT     1AH                 ;            TIME OF DAY CLOCK
           MOV     SEED,DX
           MOV     AX,SEED             ;X = SEED * MULTIPLIER mod
           MUL     MULTIPLIER          ;                       65536
           ADD     AX,ADDEND           ;SEED = (X + ADDEND) mod 65536
           MOV     SEED,AX
           MOV     CX,UPPER            ;RANGE = UPPER - LOWER + 1
           SUB     CX,LOWER
           INC     CX
           MUL     CX                  ;RANDOM = (SEED*RANGE)/65536
           ADD     DX,LOWER            ;                    + LOWER
           MOV     AX,DX
           POPF                                             
           ret     
RANDOM     ENDP                     ;END RAND
           END   RESEED   


;===================================================================
;                   MAIN.ASM
;       sets BL =1, AX = 555H
;       calls Reseed
; Calls Rand 100 times w/ lower=0 upper = 9999
; Prints values 10 numbers/line and 6 ch/number and right justify
; Counts low values (0-4999) and high values (5000-9999)
; Counts evens and odds
; Sets BL=0
; Calls Reseed
; Calls Rand 100 times w/ lower=0 upper = 9999
; Prints values 10 numbers/line and 6 ch/number and right justify
; Counts low values (0-4999) and high values (5000-9999)
; Counts evens and odds
; Prints statistics (#/200)
;===================================================================
                EXTERN   GETDEC:FAR
                EXTERN   NEWLINE:FAR
                EXTERN   PUTDEC:FAR
                EXTERN   PUTSTRNG:FAR
;==================================================================
           .MODEL  SMALL,BASIC
;===================================================================
       .STACK 256
;===================================================================
; D A T A   S E G M E N T   D E F I N I T I O N
            .FARDATA MAIN_DATA
HIGHCOUNT DW 0
LOWCOUNT DW 0
EVENCOUNT DW 0
ODDCOUNT DW 0
HIGHHEADER DB 'High numbers: '
LOWHEADER DB 'Low numbers: '
ODDHEADER DB 'Odd numbers: '
EVENHEADER DB 'Even numbers: '
;===================================================================
; C O D E   S E G M E N T   D E F I N I T I O N
;
           .CODE
   EXTERN  RANDOM : FAR, RESEED : FAR
           ASSUME  DS:NOTHING,ES:MAIN_DATA

MAIN       PROC
   MOV     AX,DGROUP           ;SET ES-REGISTER TO POINT TO
           MOV     ES,AX               ;CONSTANT DATA SEGMENT

       MOV    BL,1
       CALL    RESEED
           MOV     CX,100              ;   LOOP_COUNT = 100
NUM_LOOP:                              ;   REPEAT
           PUSH    CX                  ;      PUSH LOOP_COUNT
           MOV    AX,0                ;PUSH LOWER
           PUSH    AX             
           MOV     AX,0000             ;PUSH UPPER
           PUSH AX
       CALL RANDOM   
       CALL    PUTDEC
       CALL    NEWLINE             ;DISPLAY NEWLINE CHAR.
       CMP    AX, 5000
       JGE    HIGH_SEQUENCE
       INC     LOWCOUNT
           JMP   LOWSEQUENCE
HIGH_SEQUENCE:
       INC HIGHCOUNT
LOWSEQUENCE:
           SUB     DX, DX
           MOV     BX, 2
           DIV     BX
           CMP     DX, 0
           JNE     ODDS
           INC     EVENCOUNT
           JMP     EVENS   
ODDS:
           INC     ODDCOUNT
EVENS:     
           POP     CX                  ;      POP LOOP_COUNT
           INC     AX                  ;      NUMBER = NUMBER + 1
           LOOP    NUM_LOOP            ;      DECREMENT LOOP_COUNT
                                       ;   UNTIL LOOP_COUNT = 0
   ;MOV    0,BL
   ;CALL    RESEED
           LEA     DI, HIGHHEADER
           MOV     CX, 18
           CALL    PUTSTRNG
   MOV AX, HIGHCOUNT
   CALL PUTDEC
           CALL       NEWLINE               
           MAIN       ENDP                     
           END MAIN

dedndave

i have changed things around quite a bit - lol
i also updated the build batch file
i could not get the lib functions to work without errors, so i wrote my own
the main part works - we just need to get the random thing working

one thing i bumped into is that the library also has a function named "random"
so, i renamed yours to nrandom

veronicak5678

I can't change it too much... can you tell what's wrong with what I 've  done? And I attached the original random program so you can see what I was supposed to use for that part.

dedndave

there is a bit of a flaw in the reseed mechanism
when you call reseed, it should access the timer

the random function should then generate numbers according to the seed (no timer)
at least, that is how i think you want it to work if you want it to recreate that specific sequence (555h seed)

veronicak5678

The timer? Do you mean the clock?

All I have so far is the part that's supposed to set the seed to 555h (BL = 1) and generate numbers based on that. If I can get that working, then I'll worry about the second part (BL = 0) that uses the clock for a seed.

I hope you understand. I know this is confusing and pretty ridiculous.

dedndave

i have nice randoms - lol
is the sequence 832, 6809, 8658, and 1206 supposed to be with a range of 0 to 9999 ?