Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assignment Write Assembly language program to sort the followingnumbers, using b

ID: 3610605 • Letter: A

Question

Assignment                                                                                  

Write Assembly language program to sort the followingnumbers, using bubble sort, in signed descendingorder:

-10, -30, -25, 50, 15, 20, 35, 40, 45, 0

That is, at the end of your program, the numbers must bein the following order:

50, 45, 40, 35, 20, 15, 0, -10, -25, -30

What to Submit:

Microsoft Word document containing:

Important:

Update the last column of the following entries of ConditionalJumps table given in

Topic 3.2.CONDITIONAL JUMPS in yourhandouts

JC

JB

JNAE

Jump if carry

Jump if below

Jump if not above or equal

CF = 1

The jump is taken if the last arithmetic operation generated acarry or required a borrow. After a CMP it is taken if the unsigneddestination is smaller than the unsignedsource.

JNC

JNB

JAE

Jump if not carry

Jump if not below

Jump if above or equal

CF = 0

This jump is taken if the last arithmetic operation did notgenerated a carry or required a borrow. After a CMP it is taken ifthe unsigned destination is larger or equalto the unsigned source.

JA

JNBE

Jump if above

Jump if not below or equal

ZF =0 AND CF = 0

This jump is taken after a CMP if the unsigneddestination is larger than the unsignedsource.

JNA

JBE

Jump if not above

Jump if below or equal

ZF = 1 OR CF = 1

This jump is taken after a CMP if the unsigneddestination is smaller than or equal to theunsigned source.

JL

JNGE

Jump if less

Jump if not greater or equal

SF OF

This jump is taken after a CMP if the signeddestination is smaller than the signedsource.

JNL

JGE

Jump if not less

Jump if greater or equal

SF = OF

This jump is taken after a CMP if the signeddestination is larger than or equal to thesigned source.

JG

JNLE

Jump if greater

Jump if not less or equal

ZF = 0 AND SF =OF

This jump is taken after a CMP if the signeddestination is larger than the signedsource.

JNG

JLE

Jump if not greater

Jump if less or equal

ZF = 1 OR SF OF

This jump is taken after a CMP if the signeddestination is smaller than or equal to thesigned source.

Additional Information:

As the program starts execution, the unsorted data is loaded inmemory (M1 window) as shown in the red boundary below:

As negative numbers are stored in two’s complimentform:

To take two’s compliment of a number, following are thesteps:

Step1: Take 1 compliment of the number (withoutsign)

Step2: Add 1 to the one’s compliment(calculated in step 1)

So:

First element is -10 (decimal):

As we have defined it of size word (with the help of dw), thevalue 10 can be represented in binary as:

0000000000001010(binary)

Taking one’s compliment (simply change 0 to 1, and 1 to0):

1111111111110101

Adding 1 to the one’s compliment:

1111111111110110(binary)

FFF6(hexadecimal)

[Note that this number is also equal to 65526(in decimal) whentreated as unsigned number]

In little-Endian notation, it will be represented as:

F6FF(as shown in the screen-shot above)

JC

JB

JNAE

Jump if carry

Jump if below

Jump if not above or equal

CF = 1

The jump is taken if the last arithmetic operation generated acarry or required a borrow. After a CMP it is taken if the unsigneddestination is smaller than the unsignedsource.

JNC

JNB

JAE

Jump if not carry

Jump if not below

Jump if above or equal

CF = 0

This jump is taken if the last arithmetic operation did notgenerated a carry or required a borrow. After a CMP it is taken ifthe unsigned destination is larger or equalto the unsigned source.

JA

JNBE

Jump if above

Jump if not below or equal

ZF =0 AND CF = 0

This jump is taken after a CMP if the unsigneddestination is larger than the unsignedsource.

JNA

JBE

Jump if not above

Jump if below or equal

ZF = 1 OR CF = 1

This jump is taken after a CMP if the unsigneddestination is smaller than or equal to theunsigned source.

JL

JNGE

Jump if less

Jump if not greater or equal

SF OF

This jump is taken after a CMP if the signeddestination is smaller than the signedsource.

JNL

JGE

Jump if not less

Jump if greater or equal

SF = OF

This jump is taken after a CMP if the signeddestination is larger than or equal to thesigned source.

JG

JNLE

Jump if greater

Jump if not less or equal

ZF = 0 AND SF =OF

This jump is taken after a CMP if the signeddestination is larger than the signedsource.

JNG

JLE

Jump if not greater

Jump if less or equal

ZF = 1 OR SF OF

This jump is taken after a CMP if the signeddestination is smaller than or equal to thesigned source.

Explanation / Answer

[org 0x0100]
jmp start
data: dw -10, -30, -25, 50, 15, 20, 35, 40, 45, 0
swap: db 0
start: mov bx, 0 ; initialize array index to zero
mov byte [swap], 0 ; rest swap flag to no swaps
loop1: mov ax, [data+bx] ; load number in ax
cmp ax, [data+bx+2] ; compare with next number
jge noswap ; no swap if already in order
mov dx, [data+bx+2] ; load second element in dx
mov [data+bx+2], ax ; store first number in second
mov [data+bx], dx ; store second number in first
mov byte [swap], 1 ; flag that a swap has been done
noswap: add bx, 2 ; advance bx to next index
cmp bx, 18 ; are we at last index
jne loop1 ; if not compare next two
cmp byte [swap], 1 ; check if a swap has been done
je start ; if yes make another pass
mov ax, 0x4c00 ; terminate program
int 0x21

consult handout page no39

and give me livesaver

write m1 ds:0103 indebugger

for memory having yournumbers thanks

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote