Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 29th, 2007, 5:28 AM   #11
akioshin
Newbie
 
akioshin's Avatar
 
Join Date: Oct 2007
Posts: 6
Rep Power: 0 akioshin is on a distinguished road
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!
akioshin is offline   Reply With Quote
Old Oct 29th, 2007, 5:21 PM   #12
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 864
Rep Power: 3 lectricpharaoh is on a distinguished road
Re: tasm sorting 5 integers with array

Quote:
Originally Posted by akioshin
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 never used Turbo C, but I did use Borland C++ v3.1. I seem to recall there being a command line parameter to output assembly (as the result of compilation). Thus, you could write a small C/C++ source file, and view the assembly equivalent. I'm sure Turbo C has similar functionality.
__________________
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
lectricpharaoh is offline   Reply With Quote
Old Oct 29th, 2007, 6:27 PM   #13
akioshin
Newbie
 
akioshin's Avatar
 
Join Date: Oct 2007
Posts: 6
Rep Power: 0 akioshin is on a distinguished road
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
akioshin is offline   Reply With Quote
Old Oct 29th, 2007, 6:36 PM   #14
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 9 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Oct 29th, 2007, 11:27 PM   #15
akioshin
Newbie
 
akioshin's Avatar
 
Join Date: Oct 2007
Posts: 6
Rep Power: 0 akioshin is on a distinguished road
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
end
its working fine, is there a shorter code for this?i was just wondering
thanks a lot
akioshin is offline   Reply With Quote
Old Oct 30th, 2007, 1:45 AM   #16
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 864
Rep Power: 3 lectricpharaoh is on a distinguished road
Re: tasm sorting 5 integers with array

Quote:
Originally Posted by akioshin
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
You might want to consider using actual 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
lectricpharaoh is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:25 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC