plz any help in this code in assembly by emulator8086


the code about

a classroom has 25 students their numbers and grades in the microprocessor course are stored in the memory .it is required to rearrang them in descending order according to their grades.
the inputs are two tables . the first table contains the student number and the second one contains their grades .
the output are two tables . the first one contains the student number arranges to their grades and the second table shows these grades.

The exercise you want to do is actually a pretty simple one,
the best solution would be to have an array of dataitems
like this:
GRADE, STUDENT, GRADE, STUDENT
if the grades and student numbers were in the range of 0..255
they could be stored in a byte otherwise a larger datatype would be used.
Perform a simple bubble sort according to the grade field
of each data item and they will be sorted by grade, so that:
3, 2, 1, 3 ; grade, student, grade student
would become 1, 3, 3, 2

The following code does what you describe:

bits 16
org 100h

jmp strXt0
arr db 0x5,0x1,0x3,0x2,0x7,0x3,0x6,0x4,0x9,0x5
arr_e equ $
strXt0:
mov si, arr
mov di, arr+2
mov cx, 0
srto_l:
mov al, [si]
cmp al, [di]
jg swap
srto_retrnx:
add si, 2
add di, 2
cmp di, arr_e
jz prgnmxexit
jmp srto_l
swap:
xchg al, [di]
mov [si], al
mov al, [si+1]
xchg al, [di+1]
mov [si+1], al
inc cx
jmp srto_retrnx
prgnmxexit:
or cx, cx
jz done
jmp strXt0
done:
int 3
int 0x20

jackal hex digit hunt...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.