LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


View Poll Results: Did you find this question to be a cool post?
Yes I did! 0 0%
I like Assembly Language so yea. 0 0%
No I most certainly did not! 0 0%
No but go ahead. 1 50.00%
Stop posting maniac! 1 50.00%
Multiple Choice Poll. Voters: 2. You may not vote on this poll

Reply
  Search this Thread
Old 06-11-2014, 05:24 AM   #1
errigour
Member
 
Registered: May 2009
Posts: 366

Rep: Reputation: 6
Cool A asm proficiency question


I just want to inquire for small talk if there is a way to do
the following without all the arbitrary source.

So you don't exactly have to read it I am taking a byte and
printing its decimal number the code below is the tenth place
of the byte I am trying to print.

Please excuse the poor source but my editor has a mind of it's own.

Also answer my poll all casual comedy is welcome.
Code:
    MOV		BH, 100
    CMP 	BL, BH
    JL		PRINT_INTEGER.SKIP100
        MOV     AL, 1
	    MOV 	BH, 200
	    CMP		BL, BH
	    JL		PRINT_INTEGER.SKIP200
    	    SUB 	BL, 200
	    	MOV		BL, '2'
	    	INT     21H
	    	JMP		PRINT_INTEGER.SKIP100
    	.SKIP200
        SUB		BL, 100
        MOV		BL, '1'
        INT     21H
    .SKIP100

Last edited by errigour; 06-12-2014 at 04:13 AM.
 
Old 06-11-2014, 09:43 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
I couldn't read/understand your code.

I think you should do the following steps:

1. invent an algorithm
2. implement it in C.
3. If that works, then you can try to implement it in Assembly
 
Old 06-11-2014, 10:06 AM   #3
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
1) Why are you writing asm code for a 16 bit MS-DOS environment? If someone told you that is a place to start before learning modern asm, they misled you.

2) Why are you trying to learn ASM before you learn the basics of programming? Given the terrible formatting, I chose not to examine every detail of your code. But from an overview, I can see you are doing significant excess work as a result of not thinking like a programmer. Before you learn ASM, learn how to use more thought in order to use less code. That type of thinking applies across a range of languages.
 
1 members found this post helpful.
Old 06-11-2014, 09:26 PM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940
I will quickly agree with the foregoing.

"This is what language compilers are for." In almost every case, it's entirely pointless for you to waste your time coding a complete algorithm in assembler. The odds are much better that an optimizing compiler will do a better job at producing object-code than you will.

If you want to see how assembly-code is actually used "today," just look at the Linux kernel source-tree. You'll find that it's used in these ways:
  1. For the necessarily architecture-specific "trampoline" code that is used when the computer is first IPLed started up.
  2. For (once again, architecture-specific) subroutines which embody specific implementations of those functions. These subroutines are called by code that has been written in "C." The vast majority of the kernel is written in "C," and: There's A Reason For That.™
Quite frankly, today's microprocessors are not engineered to handle "human-generated" opcode sequences. They're designed to efficiently process the output of compilers ... which are, in turn, designed to generate outputs that can be efficiently processed. As Greyhound Bus Lines used to say, "and leave the driving to us.™" Sage advice.
 
Old 06-12-2014, 03:41 AM   #5
errigour
Member
 
Registered: May 2009
Posts: 366

Original Poster
Rep: Reputation: 6
Well i am just practicing assembly that's why I am using assembly language to do that. I was just inquiring if anyone here new any tricks. Thanks guys.
 
Old 06-12-2014, 06:16 AM   #6
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by errigour View Post
I was just inquiring if anyone here new any tricks.
Using a divide operation or even a subtract loop when you want an operation like divide is not a "trick".

Testing each of a uniform set of possibilities individually is not competent programming. There is almost always a simple way to generalize, so that far less code is needed to transform the desired input into the desired output.
 
Old 06-19-2014, 04:40 PM   #7
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940
If you are "practicing assembly," then I suggest that you confine your practice sessions only to realistic situations in which (these days ...) assembly-language programming is actually used. Just look at the /arch subdirectory of any Linux-kernel source tree: almost all of the entries in there are C-language source files with asm { ... } directives. The only real exceptions to be found are those that have to do with the "trampoline" (pre-boot ...) phase.

There is a reason for this. Modern microprocessors are not engineered to handle human-generated assembly code! They are prepared to expect the output of compilers which have been built according to the "suggestions" of the silicon-chip companies. asm {} is therefore reserved only for very short pieces of code that cannot be expressed in any other way.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
inline asm, 64-bit asm, intercepting segfaults, etc. rainbowsally Programming 0 02-04-2012 05:10 PM
IA64 ASM Question SaraiKhan Programming 29 12-18-2008 01:29 AM
asm Question Whiteghost Programming 2 09-03-2005 09:26 AM
asm question karlan Programming 6 07-16-2004 11:54 AM
ASM question zWaR Programming 2 06-26-2004 11:42 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration