News:

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

Main Menu

Help with Bubble Sorting in MASM

Started by MASMClass, May 11, 2014, 08:05:57 AM

Previous topic - Next topic

MASMClass

My classmates and I are working on a MASM project, and we have most of it down, but we need help with sorting methods. I've spent more than a few nights trying to work on this and have come up short. I am brand new to this forum, and I just don;t know who else to ask.
The assignment it to make a student report type of program. It stores first name, last name, ID number, and grade. There are also 7 procedures we need to have, such as create student, modify student, sort students by last name, first name and ID. I can make students and display their information, but I cannot sort them.
Any help is fantastic!


Ill post all of the code here. The methods that need work are SortByLastName and SortByFirstName. I think simply figuring out one will do.

INCLUDE Irvine32.inc
.data
;-----------------------------------------------------------------------------------------------------------
; Messages shown in Main Menu
;-----------------------------------------------------------------------------------------------------------

mainmenu BYTE "Student Record Database",0dh,0ah
BYTE "+-----------------------------------------------------------------------------+",0dh,0ah
BYTE "1. Create Student Record",0dh,0ah
BYTE "2. Update Student Record",0dh,0ah
BYTE "3. Find and Display Student Record",0dh,0ah
BYTE "4. Delete Student Record",0dh,0ah
BYTE "5. Sort Records Using Last Name",0dh,0ah
BYTE "6. Sort Records Using Score",0dh,0ah
BYTE "7. Display All Records",0dh,0ah
BYTE "8. Exit",0dh,0ah
BYTE "+-----------------------------------------------------------------------------+",0dh,0ah,0
prread1 BYTE "Enter a number corresponding to the task you wish to perform: ",0
errpro1 BYTE "Bad input read!  Please enter a valid number: ",0

;-----------------------------------------------------------------------------------------------------------
; Messages shown in Create Student Record
;-----------------------------------------------------------------------------------------------------------

maxmsg BYTE "The number of students is at maximum capacity.",0dh,0ah
BYTE "Please delete a student record if you wish to add a different student.",0dh,0ah,0
creaprt BYTE "Create Student Record",0dh,0ah
BYTE "+-----------------------------------------------------------------------------+",0dh,0ah,0
creapr1 BYTE "Enter Last Name of Student: ",0
creapr2 BYTE "Enter First Name of Student: ",0
creapr3 BYTE "Enter Student ID Number: ",0
creapr4 BYTE "Enter Weighted Average Score: ",0
creapr5 BYTE "The following was entered: ",0
creapr6 BYTE "Is this correct?  Enter 'y' for 'yes,' enter 'n' for 'no.'",0
creapr7 BYTE "Would you like to enter another record?  Enter 'y' for yes, 'n' for no: ",0
errpro2 BYTE "Bad input read! Please enter 'y' or 'n': ",0
nameerr BYTE "Error!  Name entered must only be letters!",0dh,0ah,0
stuiderr BYTE "Error!  Enter an ID in the range of 0-255: ",0
scoreerr BYTE "Error!  Enter a score in the range of 0-100: ",0
;-----------------------------------------------------------------------------------------------------------
; Messages shown in Find and Display Student Record
;-----------------------------------------------------------------------------------------------------------

findtitle BYTE "Find and Display Student Record",0dh,0ah,0
findbuff BYTE "+-----------------------------------------------------------------------------+",0dh,0ah,0
findpro BYTE "Enter the student ID of the record you wish to display: ",0
finderr BYTE "Non-numerical character detected!  Please enter a valid student ID number: ",0
noresult BYTE "No student record found with the ID entered.",0dh,0ah,0

;-----------------------------------------------------------------------------------------------------------
; Messages shown in Sort Student Record by Score
;-----------------------------------------------------------------------------------------------------------

sctitle BYTE "Student Records Sorted by Score",0dh,0ah,


;-----------------------------------------------------------------------------------------------------------
; Messages shown in Display All Records
;-----------------------------------------------------------------------------------------------------------

allprot BYTE "All Student Records",0
buffpr BYTE "+------------------+-------------------+-------------------+------------------+",0
sidebf BYTE "|",0
lnamepr BYTE "Last Name",0
fnamepr BYTE "First Name",0
stuidpr BYTE "Student ID",0
avgscpr BYTE "Average Score",0

;-----------------------------------------------------------------------------------------------------------
; Student Information Parameters and Arrays
;-----------------------------------------------------------------------------------------------------------

stucount DWORD 0 ; counts the number of students entered into database
nameoff DWORD 0 ; offsets each name, dependent on name length
MAXNUMST = 4 ; maximum number of students that can be entered into database
NAMELEN = 10 ; maximum length of student name (10) plus null character
lastname BYTE NAMELEN DUP(0)
firstname BYTE NAMELEN DUP(0)
studentid DWORD 0
averscore DWORD 0
lnamearr BYTE MAXNUMST*NAMELEN DUP(0) ; last name array
fnamearr BYTE MAXNUMST*NAMELEN DUP(0) ; first name array
stuidnum DWORD MAXNUMST DUP(0) ; student id array
avgscore DWORD MAXNUMST DUP(0) ; average score array


.code

main PROC
mov ebx,0
L: call Clrscr

call DisplayMainMenu
call ReadMenuTask
call DumpRegs

T1: cmp eax,1
jne T2
call CreateRecord
jmp L
T2: cmp eax,2
jne T3
call UpdateRecord
jmp L
T3: cmp eax,3
jne T4
call FindDisplayRecord
jmp L
T4:  cmp eax,4
jne T5
call DeleteRecord
jmp L
T5: cmp eax,5
jne T6
call SortByLastName
jmp L
T6: cmp eax,6
jne T7
call SortByScore
jmp L
T7: cmp eax,7
jne T8
call DisplayAllRecords
jmp L
T8: cmp eax,8
je EX

EX: exit

main ENDP


DisplayMainMenu PROC USES edx

mov edx,OFFSET mainmenu
call WriteString
call Crlf
mov edx,OFFSET prread1
call WriteString

ret
DisplayMainMenu ENDP

ReadMenuTask PROC USES edx

L: call ReadDec
cmp eax,9
jb S1
call Crlf
mov edx,OFFSET errpro1
call WriteString
jmp L
S1: cmp eax,0
ja S2
call Crlf
mov edx,OFFSET errpro1
call WriteString
jmp L
S2: ret
ReadMenuTask ENDP

CreateRecord PROC USES ecx edx esi

mov esi,stucount
T1: cmp esi,MAXNUMST
jne T2
call Clrscr
mov edx,OFFSET maxmsg ; Student count at maximum capacity, need to delete
call WriteString ; records to add more

call Crlf
call WaitMsg
jmp EX

T2: call Clrscr

mov edx,OFFSET creaprt
call WriteString

L1: call Crlf
mov edx,OFFSET creapr1 ; Enter Last Name of Student:
call WriteString
mov edx,OFFSET lastname
mov ecx,NAMELEN
call ReadString
call LastNameCheck
cmp eax,0 ; EAX = 0: not all characters were letters
jne L2
call Crlf
mov edx,OFFSET nameerr
call WriteString
jmp L1

L2: call Crlf
mov edx,OFFSET creapr2 ; Enter First Name of Student:
call WriteString
mov edx,OFFSET firstname
mov ecx,NAMELEN
call ReadString
call FirstNameCheck
cmp eax,0 ; EAX = 0: not all characters were letters
jne L3
call Crlf
mov edx,OFFSET nameerr
call WriteString
jmp L2

L3: call Crlf
mov edx,OFFSET creapr3 ; Enter Student ID Number:
call WriteString
L4: call ReadInt
cmp eax,0
jb EI
cmp eax,255
ja EI
mov stuidnum[esi*TYPE stuidnum],eax
call Crlf
jmp L5

EI: mov edx,OFFSET stuiderr
call WriteString
jmp L4

L5: mov edx,OFFSET creapr4 ; Enter Weighted Average Score:
call WriteString
L6: call ReadInt
cmp eax,0
jb EC
cmp eax,100
ja EC
mov avgscore[esi*TYPE avgscore],eax
call Crlf
jmp L7

EC: mov edx,OFFSET scoreerr
call WriteString
jmp L6

L7: mov edx,OFFSET creapr5 ; The following was entered:
call WriteString
call Crlf
call Crlf
mov edx,OFFSET lastname
call WriteString ; Prints last name
call Crlf
mov edx,OFFSET firstname
call WriteString ; Prints first name
call Crlf
mov eax,stuidnum[esi*TYPE stuidnum]
call WriteDec ; Prints student ID
call Crlf
mov eax,avgscore[esi*TYPE avgscore]
call WriteDec ; Prints average score
call Crlf
call Crlf

mov edx,OFFSET creapr6
call WriteString ; Is this correct?  Enter 'y' for yes, enter 'n' for no:
S1: call ReadChar
call Crlf
call Crlf
cmp al,'n'
je T1
cmp al,'y'
je S2
mov edx,OFFSET errpro2
call WriteString
jmp S1

S2: call WriteToArrays
inc esi
inc stucount
add nameoff,NAMELEN

S3: mov edx,OFFSET creapr7 ; Would you like to enter another record?  Enter 'y' for yes, 'n' for no:
call WriteString
call ReadChar
cmp al, 'n'
je EX
cmp al, 'y'
je T1
mov edx,OFFSET errpro2
call WriteString
jmp S3

EX: ret
CreateRecord ENDP

WriteToArrays PROC USES ecx esi

mov esi,0
mov ecx,NAMELEN
L1: mov al,lastname[esi]
add lnamearr[ebx],al
mov al,firstname[esi]
add fnamearr[ebx],al
inc esi
inc ebx
loop L1

ret
WriteToArrays ENDP

LastNameCheck PROC USES ecx edx esi

mov eax,1 ; EAX is true
and lastname[0],0DFh ; Makes first character uppercase
mov esi,0
mov ecx, LENGTHOF lastname

L1: cmp lastname[esi],0
je EX
cmp esi,0 ; Checks to see if the first character in name
jne SK ; Skips if not
cmp lastname[0],41h
jb ER
cmp lastname[0],5Ah
ja ER
jmp L2

SK: or lastname[esi],20h ; Makes every character after the first lowercase
cmp lastname[esi],61h
jb ER ; Error if less than ASCII value for 'a'
cmp lastname[esi],7Ah
ja ER ; Error if greater than ASCII value for 'z'
jmp L2

ER: mov eax,0 ; EAX is false, character is not a letter
jmp EX

L2: inc esi
loop L1

EX: ret
LastNameCheck ENDP

FirstNameCheck PROC USES ecx edx esi

mov eax,1 ; EAX is true
and firstname[0],0DFh ; Makes first character uppercase
mov esi,0
mov ecx, LENGTHOF firstname

L1: cmp firstname[esi],0
je EX
cmp esi,0 ; Checks to see if the first character in name
jne SK ; Skips if not
cmp firstname[0],41h
jb ER
cmp firstname[0],5Ah
ja ER
jmp L2

SK: or firstname[esi],20h ; Makes every character after the first lowercase
cmp firstname[esi],61h
jb ER ; Error if less than ASCII value for 'a'
cmp firstname[esi],7Ah
ja ER ; Error if greater than ASCII value for 'z'
jmp L2

ER: mov eax,0 ; EAX is false, character is not a letter
jmp EX

L2: inc esi
loop L1

EX: ret
FirstNameCheck ENDP

SortByLastName PROC
call Clrscr


mov ecx, NAMELEN
mov edx, LENGTHOF lnamearr
bs_o:
xor ebp,ebp
bs_i:
mov eax, DWORD PTR [edx+ebp*4+4]
cmp DWORD PTR [edx+ebp*4],eax
jb S1
xchg eax, DWORD PTR [edx+ebp*4]
mov DWORD PTR [edx+ebp*4+4], eax
S1:
add ebp,1
cmp ebp,ecx
jb bs_i
loop bs_o
pop ebp

call WriteHeader

call WaitMsg
ret
SortByLastName ENDP

SortByScore PROC USES ecx edx esi
call Clrscr

mov edx,OFFSET sctitle
call WriteString

call WriteHeader

COMMENT @
mov esi,1
mov ecx,stucount
L1: mov eax,avgscore[esi]
cmp eax,avgscore[esi-1]
jbe L2
@

call WaitMsg
ret
SortByScore ENDP

DisplayAllRecords PROC USES eax ebx ecx edx esi
call Clrscr

mov edx,OFFSET allprot
call WriteString
call Crlf
call Crlf

call WriteHeader

call WriteTable

call Crlf
call Crlf
call WaitMsg ; Temporary wait message
ret
DisplayAllRecords ENDP


WriteHeader PROC USES edx
mov dh,2
mov dl,0
call Gotoxy
mov edx,OFFSET buffpr ; Writes horizontal line across the screen
call WriteString
call Crlf

mov edx,OFFSET sidebf ; Writes a vertical boundary
call WriteString

mov edx,OFFSET lnamepr ; Writes "Last Name"
call WriteString

mov dh,3
mov dl,19
call Gotoxy
mov edx,OFFSET sidebf ; Writes boundary between "Last Name" & "First Name"
call WriteString

mov edx,OFFSET fnamepr ; Writes "First Name"
call WriteString

mov dh,3
mov dl,39
call Gotoxy
mov edx,OFFSET sidebf ; Writes boundary between "First Name" & "Student ID"
call WriteString

mov edx,OFFSET stuidpr ; Writes "Student ID"
call WriteString

mov dh,3
mov dl,59
call Gotoxy
mov edx,OFFSET sidebf
call WriteString

mov edx,OFFSET avgscpr ; Writes "Average Score"
call WriteString

mov dh,3
mov dl,78
call Gotoxy
mov edx,OFFSET sidebf
call WriteString
call Crlf

mov edx,OFFSET buffpr
call WriteString
call Crlf
ret
WriteHeader ENDP

WriteTable PROC USES eax ecx edx esi

mov esi,0
mov ecx,NAMELEN
mov dh,5
L1: mov dl,0
call Gotoxy
LI: mov al,lnamearr[esi]
cmp al,0
je LO
call WriteChar
inc esi
loop LI

LO: inc esi
cmp esi,LENGTHOF lnamearr
je S1
cmp lnamearr[esi],0
je LO
mov ecx,NAMELEN
inc dh
jmp L1

S1:
mov esi,0
mov ecx,NAMELEN
mov dh,5
F1: mov dl,20
call Gotoxy
FI: mov al,fnamearr[esi]
cmp al,0
je FO
call WriteChar
inc esi
loop FI

S2:  call Crlf

FO: inc esi
cmp esi,LENGTHOF fnamearr
je S3
cmp fnamearr[esi],0
je FO
mov ecx,NAMELEN
inc dh
jmp F1
S3:
mov esi,0
mov ecx,stucount
mov dh,5
N1: mov dl,40
call Gotoxy
mov eax,stuidnum[esi*TYPE stuidnum]
call WriteDec
mov dl,60
call Gotoxy
mov eax,avgscore[esi*TYPE avgscore]
call WriteDec
inc esi
add dh,2
loop N1
ret
WriteTable ENDP
END main

Let me know if you need any more information. I've cut most of the PROC out so I can post into this forum.

Thank you in advance!

Added code tags

jj2007

    mov ecx, NAMELEN
    mov edx, LENGTHOF lnamearr
bs_o:
    xor ebp,ebp
bs_i:
    mov eax, DWORD PTR [edx+ebp*4+4]


That won't fly. Not surprisingly, it crashes with an access violation.

Could you please re-post this procedure with a decent level of comments?

MASMClass

Quote from: jj2007 on May 11, 2014, 08:56:18 AM
   
Could you please re-post this procedure with a decent level of comments?

Sure

SortByLastName PROC
call Clrscr

   
   mov ecx, NAMELEN                          ;length of the maximum characters per name in array
   mov edx, LENGTHOF lnamearr         ; the total length of the last name array
bs_o:
   xor ebp,ebp                                     
bs_i:
   mov eax, DWORD PTR [edx+ebp*4+4]   ; trying to give eax the value of the first name
   cmp DWORD PTR [edx+ebp*4],eax         ; comparing the second last name to the first last name
   jb S1                                                        ; if already in alphabetical order, skip
   xchg eax, DWORD PTR [edx+ebp*4]       ; if not in order then exchange them
   mov DWORD PTR [edx+ebp*4+4], eax    ; move eax to the next position for comparison
S1:
   add ebp,1                                                ; increment ebp
   cmp ebp,ecx                                             ; compares ebp to ecx
   jb bs_i                                                      ; repeat if not complete
   loop bs_o
   pop ebp

   call WriteHeader                                      ; writes the names to the menu

   call WaitMsg                                              ;"press any key to continue"
   ret                                                            ; return values to previous conditions
SortByLastName   ENDP

hutch--

Don't be afraid to have a look at the MASM32 example code "bubble.asm" in the "exampl06\bubble" directory.

RuiLoureiro

Quote from: MASMClass on May 11, 2014, 10:15:17 AM
Quote from: jj2007 on May 11, 2014, 08:56:18 AM
   
Could you please re-post this procedure with a decent level of comments?

Sure

SortByLastName PROC
call Clrscr

   
   mov ecx, NAMELEN                          ;length of the maximum characters per name in array
   mov edx, LENGTHOF lnamearr         ; the total length of the last name array
bs_o:
   xor ebp,ebp                                     
bs_i:
   mov eax, DWORD PTR [edx+ebp*4+4]   ; trying to give eax the value of the first name
   cmp DWORD PTR [edx+ebp*4],eax         ; comparing the second last name to the first last name
   jb S1                                                        ; if already in alphabetical order, skip
   xchg eax, DWORD PTR [edx+ebp*4]       ; if not in order then exchange them
   mov DWORD PTR [edx+ebp*4+4], eax    ; move eax to the next position for comparison
S1:
   add ebp,1                                                ; increment ebp
   cmp ebp,ecx                                             ; compares ebp to ecx
   jb bs_i                                                      ; repeat if not complete
   loop bs_o
   pop ebp

   call WriteHeader                                      ; writes the names to the menu

   call WaitMsg                                              ;"press any key to continue"
   ret                                                            ; return values to previous conditions
SortByLastName   ENDP
Hi
Quote
SortByLastName PROC
call Clrscr

   
    mov ecx, NAMELEN                          ;length of the maximum characters per name in array
    mov edx, LENGTHOF lnamearr         ; the total length of the last name array
bs_o:
    xor ebp,ebp                                     
bs_i:
    mov eax, DWORD PTR [edx+ebp*4+4]   ; trying to give eax the value of the first name
    cmp DWORD PTR [edx+ebp*4],eax         ; comparing the second last name to the first last name
    jb S1                                                        ; if already in alphabetical order, skip
    xchg eax, DWORD PTR [edx+ebp*4]       ; if not in order then exchange them
    mov DWORD PTR [edx+ebp*4+4], eax    ; move eax to the next position for comparison
S1:
    add ebp,1                                                ; increment ebp
    cmp ebp,ecx                                             ; compares ebp to ecx
   jb bs_i                                                      ; repeat if not complete
    loop bs_o
    pop ebp     <<<<<<<<<<<<<<<< Why this HERE ??? <<<<<<<<<<<<

   call WriteHeader                                      ; writes the names to the menu

   call WaitMsg                                              ;"press any key to continue"
   ret                                                            ; return values to previous conditions
SortByLastName   ENDP

Could you explain why do you use «pop ebp» ?
Why do you use ebp and not ebx, for example ?

MASMClass

Alright, I threw out the old sorting procedure, and I am trying something new. I thought that this proc would work better, so I'm posting it now.
If you have any idea what is wrong with it, please describe to me in detail what it is. I'm still very new to MASM, and I don't know my way around it very well.

;-----------------------------------------------------------------------------------------------------------
SortByLastName PROC
;-----------------------------------------------------------------------------------------------------------
call Clrscr

_start:
   ;-----------------------
   ;Size of the array in
   ;ecx
   ;-----------------------
   mov ecx, LENGTHOF lnamearr
   mov ebp, LENGTHOF lnamearr
   mov ebx, [LENGTHOF lnamearr]
again:
   call bubble_sort
   dec ebp
   jnz again
   
   ;----------------
   ;Exit the program
   ;----------------
   mov eax, 1

   ;-------------------------------------...
   ;The base address of the array is in ebx
   ;The size of the array is in ecx
   ;-------------------------------------...
bubble_sort:
   push ebx
   push ecx
start_sorting:
   mov eax, [ebx]
   mov edx, [ebx+10]
   cmp eax, edx
   jg swap
   jmp next
swap:
   xchg eax, [ebx+10]
   mov [ebx], eax
next:
   add ebx, 10
   loop start_sorting
   pop ecx
   pop ebx
   ret
SortByLastName   ENDP


Just assume that I am only going to run this once, to switch two names around. i.e. The first and second last name are alphabetically incorrect, and I want to switch them.
The first name should be in [ebx 1-10] and the second should be in [ebx 11-20].
Thanks for all the help. It is greatly appreciated.
If preferred, I can also show my screen during a skype call, to work with any of you to make sure this gets done.
You see, this project is due tonight at 11:59 pm Central USA time. I am extremely desperate.

jj2007

Quote from: MASMClass on May 12, 2014, 06:42:07 AM
   mov ebx, [LENGTHOF lnamearr]
...
   ;The base address of the array is in ebx

Sure?

RuiLoureiro

Hi MASMClass

First: i dont like to use Irvine32 (i have no time to lose with it);

Second: you say, «The first name should be in [ebx 1-10] and
                  the second should be in [ebx 11-20].»
                 
        So, each has 10 bytes. If i am understanding the problem
        The Last Name starts at index EBX=10 and end at index EBX=19
        (10 bytes). So if what i am saying is correct, i dont understand
        why you compare only 4 bytes at a time, but we need to compare
        10 bytes, not 4 (and we need to change 10 bytes also, not 4).
       
        HERE:
                mov eax, [ebx]                 ; eax are only 4 bytes
                mov edx, [ebx+10]           ; edx are only 4 bytes
                cmp eax, edx
                ...
               
        It seems that each last name have only 4 bytes

Third: EBX must be the starting address of the last name array
           I dont understand this:

          «mov ebx, [LENGTHOF lnamearr]»

Try to see this:

_LastNameArray  db "This name1"         ; first name,  length=10    -> index 0
                            db "That name2"         ; second name, length=10    -> index 1
                and so on
                            db "Last nameN"         ; last name,   length=10    -> index N-1

The starting address:

                mov     esi, offset _LastNameArray
       
Number of names:
                mov     ecx, 20         ; 20 names for example
                mov     edx, 10         ; length of each name

                mov     ebx, esi
                add     ebx, edx        ; is the address of the second name

                mov     al, [esi]
                cmp     al, [ebx]       ; compare the first byte of the first name
                                        ; with the first byte of the second name
               
                and so on

               
    Think about this.
    Good luck  :t

;-----------------------------------------------------
SortByLastName PROC
;-----------------------------------------------------
call Clrscr

_start:
   ;-----------------------
   ;Size of the array in
   ;ecx
   ;-----------------------
   mov ecx, LENGTHOF lnamearr
   mov ebp, LENGTHOF lnamearr
   mov ebx, [LENGTHOF lnamearr]
again:
   call bubble_sort
   dec ebp
   jnz again
   
   ;----------------
   ;Exit the program
   ;----------------
   mov eax, 1

   ;-------------------------------------...
   ;The base address of the array is in ebx
   ;The size of the array is in ecx
   ;-------------------------------------...
bubble_sort:
   push ebx
   push ecx
start_sorting:
   mov eax, [ebx]
   mov edx, [ebx+10]
   cmp eax, edx
   jg swap
   jmp next
swap:
   xchg eax, [ebx+10]
   mov [ebx], eax
next:
   add ebx, 10
   loop start_sorting
   pop ecx
   pop ebx
   ret
SortByLastName   ENDP

dedndave

i am a little surprised that none of the other members have addressed the overall design

normally, we might create a structure that contains all the entries for each student
when a new student record is added, it's always added at the end
currently, you have 10 + 10 + 4 + 4 bytes, or 28 bytes
well - you could use another entry for credit hours, as the current method doesn't allow the score to be updated
and, 10 characters for first and last name might be a bit limited
assuming those things are ok....
STUDENT_RECORD STRUCT
  dwStudentID dd ?
  dwScore     dd ?
  szLast      db 10 dup(?)
  szFirst     db 10 dup(?)
STUDENT_RECORD ENDS


now, rather than sorting records, we might create an index array
the array might be made of bytes that indicate a record index number (0 to 255)
or words or dwords, if more students are to be accommodated
the array might as well contain DWORD pointers to each record

you can create an array for each sort criteria, last name, first name, ID, score
rather than ordering the record array, you order the index array(s) according to sort criteria
this should be much more efficient, particularly if the number of records is large

RuiLoureiro

 :biggrin:
Hi Dave,
      The overall design is not my problem and ...
      Well, write the procedures you need to solve it
      and help him, if you want Dave.
      I have no much time.

      You said: «...this should be much more efficient...»
      but he wants one way to solve the problem as far
      as i know. To start learning assembly
      we dont need to start doing complex things (my opinion).

dedndave

i don't have a lot of spare time nowdays, either, Rui
but, i know what an instructor might like to see to get an A   :biggrin:
a basic indexed database is probably what he's after
it's a little tricky to order an index list - not the same as sorting the data, itself

Gunther

Dave,

Quote from: dedndave on May 12, 2014, 08:58:11 PM
it's a little tricky to order an index list - not the same as sorting the data, itself

that's right. But I would write that in C or BASIC and translate it to assembly language later. With a high optimization level you have to give you a lot of effort to beat the compiler. It's possible, but not easy.

Gunther
You have to know the facts before you can distort them.

dedndave

it's an assembly language class though, Gunther   :biggrin:

EDIT: earlier, i said that a new record always went at the end
but, it could be written so that deleted records remain, and a new one might replace a previously deleted one

now - all that may seem a little complicated
but, it's not a single programmer - it's a team
break it up and let each team member take a piece   :t

Gunther

Dave,

Quote from: dedndave on May 12, 2014, 09:20:47 PM
it's an assembly language class though, Gunther   :biggrin:

yes, of course, but it's not forbidden to do the task at home first in C before you translate it into assembly language. If that's done, you have to set one compiler switch and you have the complete assembly language source. That would be my basis to work further. with gcc you must do:

gcc -S MySource.c

The compiler generates a file MySource.s which contains the compiler generated assembly source. With Borland it was -S too, I think. With Visual C exists a similar switch, I'm sure. So what?

Gunther
You have to know the facts before you can distort them.

RuiLoureiro

Quote from: dedndave on May 12, 2014, 08:58:11 PM
i don't have a lot of spare time nowdays, either, Rui
but, i know what an instructor might like to see to get an A   :biggrin:
a basic indexed database is probably what he's after
it's a little tricky to order an index list - not the same as sorting the data, itself
Yes Dave, we can do it with linked list also, it is so easy and he gets AA!  :biggrin:
But Dave, you should explain to him what to do to get a indexed database.
Some time ago i posted something about it here.