Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Prerequisites before learning Assembly[Lesson1]
07-06-2009, 02:32 PM (This post was last modified: 07-06-2009 02:38 PM by Back_track.)
Post: #1
Prerequisites before learning Assembly[Lesson1]
well since matt. was learning assembly i thought i should give it an attempt so far i have barely got to the language because all the math required so i will make a tutorial on how to use math for assembly bare with me

ok lets start don't even download an assembler yet( you won't need it for this tutorial )

now alot of you know that computers use binary code
i.e
1010110

and the number system that we use is decimal now lets see how we can convert them

Lesson 1 Binary To Decimal
ok here is our string of binary code
Code:
101110
Now lets start solving it
ok analyze how many numbers how many numbers are in the string i count 6
ok this should be organized like this to solve:
Code:
1*2^5 =
0*2^4 =
1*2^3 =
1*2^2 =
1*2^1 =
0*2^0 =
Now Solve that ( keep in mind that the problems with 0's in them are automatically 0 except for at the end with anything to the power of zero)
and when you are done multiplying add up the answers and you should get your decimal answer

Now Here is another one and trust me work theses out with pen and paper it will help you tremendously
Binary
Code:
1110001111
there is ten in that one now how is how would it be worked out?
Code:
1*2^9 = 512
1*2^8 = 256
1*2^7 = 128
0*2^6 = 0
0*2^5 = 0
0*2^4 = 0
1*2^3 = 8
1*2^2 = 4
1*2^1 = 2
1*2^0 = 1
ok now we add them up
Code:
512+256+128+8+4+2+1 = 911
the answer in decimal is 911
[Image: 0706090027.jpg]
See i did it with pen and paper ^^
Oh and i'll be making more of these tutorials

"Character is determined more by the lack of certain experiences than by those one has had."
Friedrich Nietzsche
Visit this user's website Find all posts by this user
Quote this message in a reply
07-06-2009, 06:13 PM
Post: #2
RE: Prerequisites before learning Assembly[Lesson1]
WOW great tut. I made an dec to bin converter, because i knew how to. But now i can make an bin to dec converter, thanks to you !
I didn't know formula, so i couldn't !
THX for formula, and this is code for bin to dec converter in TPW :
Code:
program binary_to_decimal;
uses wincrt;
var
a:array[1..100] of 0..1;
s:string;
i,n,g:integer;
function power(k,z:integer):integer;
var
   i,p:integer;
begin
   p:=1;
   for i:=1 to z do
   p:=p*k;
   power:=p;
end;
function binary_check(s:string):boolean;
var
   i:integer;
   b:boolean;
begin
  b:=false;
  for i:=1 to length(s) do
   if b=false then
    if  (s[i]<>'1') and (s[i]<>'0') then
      b:=true;
  if b=false then
    binary_check:=true
  else
    binary_check:=false;
end;
begin
writeln('Binary to decimal converter by Dr DEBCOL !');
writeln('THX to Back_track for formula !');
repeat
  begin
   writeln('Enter binary number !');
   readln(s);
  end;
until binary_check(s);
for i:=1 to length(s) do
if s[i]='1' then
  a[i]:=1
else
  a[i]:=0;
n:=length(s)-1;
g:=0;
for i:=1 to n+1 do
begin
g:=g+a[i]*power(2,n);
  n:=n-1;
end;
writeln('Decimal is ',g);
end.

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
07-07-2009, 11:18 AM
Post: #3
RE: Prerequisites before learning Assembly[Lesson1]
Hahaha thanks man, I feel so special.

I Heart C++
Find all posts by this user
Quote this message in a reply
10-11-2009, 04:45 PM
Post: #4
RE: Prerequisites before learning Assembly[Lesson1]
(07-06-2009 06:13 PM)drdebcol Wrote:  WOW great tut. I made an dec to bin converter, because i knew how to. But now i can make an bin to dec converter, thanks to you !
I didn't know formula, so i couldn't !
THX for formula, and this is code for bin to dec converter in TPW :
Code:
program binary_to_decimal;
uses wincrt;
var
a:array[1..100] of 0..1;
s:string;
i,n,g:integer;
function power(k,z:integer):integer;
var
   i,p:integer;
begin
   p:=1;
   for i:=1 to z do
   p:=p*k;
   power:=p;
end;
function binary_check(s:string):boolean;
var
   i:integer;
   b:boolean;
begin
  b:=false;
  for i:=1 to length(s) do
   if b=false then
    if  (s[i]<>'1') and (s[i]<>'0') then
      b:=true;
  if b=false then
    binary_check:=true
  else
    binary_check:=false;
end;
begin
writeln('Binary to decimal converter by Dr DEBCOL !');
writeln('THX to Back_track for formula !');
repeat
  begin
   writeln('Enter binary number !');
   readln(s);
  end;
until binary_check(s);
for i:=1 to length(s) do
if s[i]='1' then
  a[i]:=1
else
  a[i]:=0;
n:=length(s)-1;
g:=0;
for i:=1 to n+1 do
begin
g:=g+a[i]*power(2,n);
  n:=n-1;
end;
writeln('Decimal is ',g);
end.

NIce code I also made a binary to decimal convert in pascal back in 07

http://www.planet-source-code.com/vb/scr...7&lngWId=7
Visit this user's website Find all posts by this user
Quote this message in a reply
10-11-2009, 07:02 PM (This post was last modified: 10-11-2009 07:03 PM by drdebcol.)
Post: #5
RE: Prerequisites before learning Assembly[Lesson1]
(10-11-2009 04:45 PM)codecaine Wrote:  
(07-06-2009 06:13 PM)drdebcol Wrote:  WOW great tut. I made an dec to bin converter, because i knew how to. But now i can make an bin to dec converter, thanks to you !
I didn't know formula, so i couldn't !
THX for formula, and this is code for bin to dec converter in TPW :
Code:
program binary_to_decimal;
uses wincrt;
var
a:array[1..100] of 0..1;
s:string;
i,n,g:integer;
function power(k,z:integer):integer;
var
   i,p:integer;
begin
   p:=1;
   for i:=1 to z do
   p:=p*k;
   power:=p;
end;
function binary_check(s:string):boolean;
var
   i:integer;
   b:boolean;
begin
  b:=false;
  for i:=1 to length(s) do
   if b=false then
    if  (s[i]<>'1') and (s[i]<>'0') then
      b:=true;
  if b=false then
    binary_check:=true
  else
    binary_check:=false;
end;
begin
writeln('Binary to decimal converter by Dr DEBCOL !');
writeln('THX to Back_track for formula !');
repeat
  begin
   writeln('Enter binary number !');
   readln(s);
  end;
until binary_check(s);
for i:=1 to length(s) do
if s[i]='1' then
  a[i]:=1
else
  a[i]:=0;
n:=length(s)-1;
g:=0;
for i:=1 to n+1 do
begin
g:=g+a[i]*power(2,n);
  n:=n-1;
end;
writeln('Decimal is ',g);
end.

NIce code I also made a binary to decimal convert in pascal back in 07

http://www.planet-source-code.com/vb/scr...7&lngWId=7
Good job, your solution is good, only you added isbinary() function and i didn't.
But when we talk about number systems, i have number system converter in Pascal, from base 2 to 16 (from binary to hexadecimal) of any number system, for example from base 5 to decimal, you convert easily.
There is any_to_dec and dec_to_any, also there is function inttostr() which i made !
You have it here :
http://www.pro9ramming.com/number-systems-t-278.html

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
10-12-2009, 02:58 AM (This post was last modified: 10-12-2009 03:03 AM by G4143.)
Post: #6
RE: Prerequisites before learning Assembly[Lesson1]
You have a good start there...for me assembler has interested me mainly for understanding of how the pieces fit together. So that translates to a lot of address resolution and byte/bit counting, all in all very tedious but rewarding in the end...G4143

Keep it up, general understanding of the machine will help in most programming endeavors
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: