![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Newbie
Join Date: Oct 2007
Posts: 6
Rep Power: 0
![]() |
Re: tasm sorting 5 integers with array
yeah at first i was trying to use the insertion sort, because i have a turbo c code for insertion sort but its kinda hard for me to convert it to assembly code, i really appreciate all your help im only 19 years old dont have a lot of experience in assembly programming, in my country we say thank you as "salamat" hoping that i could be in your level of thinking soon thanks!
|
|
|
|
|
|
#12 | |
|
Caffeinated Neural Net
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 864
Rep Power: 3
![]() |
Re: tasm sorting 5 integers with array
Quote:
__________________
A man's knowledge is like an expanding sphere, the surface corresponding to the boundary between the known and the unknown. As the sphere grows, so does its surface; the more a man learns, the more he realizes how much he does not know. Hence, the most ignorant man thinks he knows it all. - L. Sprague de Camp |
|
|
|
|
|
|
#13 |
|
Newbie
Join Date: Oct 2007
Posts: 6
Rep Power: 0
![]() |
Re: tasm sorting 5 integers with array
wow i try to check that out, our teacher never taught that but i will try to explore more in turbo c, thanks by the way
|
|
|
|
|
|
#14 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 9
![]() |
Re: tasm sorting 5 integers with array
I'm not saying that every compiler ever invented will output assembler as a side effect, but I've never used one that won't.
VC++ 2008 Beta, for instance, will output assembly only, assembly with machine code, assembly with source, or assembly with machine code and source, or none of the above. When debugging, one may choose to view the assembly and machine code, even if separate output is not enabled.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#15 |
|
Newbie
Join Date: Oct 2007
Posts: 6
Rep Power: 0
![]() |
Re: tasm sorting 5 integers with array
hi everyone i've finish the problem sorting 5 intergers here is my code
extrn readnum:near
extrn writenum:near
extrn new_line:near
extrn clearscreen:near
public num
.286
.model small
printStr macro str
pusha
lea dx, str
mov ah, 9
int 21h
popa
endm
.stack 0
.data
msg db, 10, 13, 'Please enter one digit number: $'
num dw 0
num2 dw 0
ar1 dw 5 dup(?)
.code
mov ax, @data
mov ds, ax
mov bx, offset ar1
mov cx, 5
aloop:
printStr msg
call readnum
mov ax, num
mov [bx], ax
add bx, 2
loop aloop
sub si, si
sub di, di
mov num2, 8
@@loop_i:
mov di, si
; add di, 2 ; di + 2
@@loop_j:
mov bx, offset ar1
mov ah, [bx+si]
mov al, [bx+di]
cmp ah, al ; if (ar1[i] <= ar1[j]) then no swap
jle @@no_swap
mov [bx+si], al ; else swap
mov [bx+di], ah
@@no_swap:
add di, 2
cmp di, 8 ; (compare with bound)
jle @@loop_j ; if below or equal, then go to @@loop_j
add si, 2
cmp si, 8
jle @@loop_i
;for displaying the array
disp1:
mov bx, offset ar1
mov cx, 5
disp:
mov ax,[bx]
mov num, ax
call new_line
call writenum
add bx, 2
loop disp
mov ah, 4ch
int 21h
endthanks a lot |
|
|
|
|
|
#16 | |
|
Caffeinated Neural Net
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 864
Rep Power: 3
![]() |
Re: tasm sorting 5 integers with array
Quote:
int variables. With most 16-bit DOS compilers, an int is 16 bits, so you can use the word-sized regs, rather than the byte ones. I realize you're looking to sort single-digit numbers, but more functionality is always good.Another thing to consider is what registers are safe to clobber, if you're mixing assembly with another language, such as C. When the compiler generates code, it uses certain registers. Some are safe to modify between statements, and some are not. For many old DOS compilers, you can modify AX, BX, CX, and DX, as well as SI and DI (the latter two are only safe if the compiler isn't using register variables). BP is pretty much never safe to use; higher-level languages use it to maintain the stack frame. Of the segment registers, you should never modify SS, unless you're writing stack-switching code (a bit beyond your current skills, I expect). DS is okay to muck with, but put it back when you're done. ES may be okay, depending on the compiler, and the 386+ FS and GS registers are usually fine to use (older compilers are often oblivious to their existence). All of this is based on my experience with old 16-bit DOS compilers, and your compiler might differ. In particular, 32-bit compilers such as DJGPP have different clobber registers. If you're unsure, the safest thing is to push the regs at the start of your routine, and pop 'em off after.
__________________
A man's knowledge is like an expanding sphere, the surface corresponding to the boundary between the known and the unknown. As the sphere grows, so does its surface; the more a man learns, the more he realizes how much he does not know. Hence, the most ignorant man thinks he knows it all. - L. Sprague de Camp |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| sorting an array by field | cwl157 | C | 4 | Apr 4th, 2007 2:48 PM |
| Sorting an array of objects | oNe8 | Java | 2 | Feb 22nd, 2006 10:59 PM |
| Sorting without a large array | sim_maroon | C | 12 | Nov 21st, 2005 8:45 PM |
| Sorting a Numeric Array | little_valaree | Java | 2 | Nov 21st, 2005 11:00 AM |
| Installing IPB 2.03 | bh4575 | Other Web Development Languages | 0 | Apr 23rd, 2005 2:36 AM |