Newsletter: Heroin Phentermine not working Lethal doses klonopin wellbrutrin xanax Xanax no prescription needed Tolmetin Drug phentermine 37.5 pdr Naproxen Viagra faq Eulexin Generic lowest price viagra Tramadol used for Online phentermine sale Prescription for viagra Viagra conviaindications Secobarbital Etoposide Tramadol sales Soma seed Acetylcholine Adipex phentermine vs Ethchlorvynol Phentermine np Flagyl Phentermine 37 5mg and mastercard Cialis overnight Pyrimethamine Carbenicillin Hydroxyzine Bayer Nortriptyline Viagra sale online Hetacillin Generic viagra no perscription needed Viagra useage Xanax withdrawl symptoms Phentermine and diet pill Buy Famvir Canadian online pharmacy xanax Viagra interaction Phentermine free delivery Generic xanax 2mg Cialis compare levivia viagra No perscription viagra Levofloxacin Levoxyl Buy online order viagra Xanax withdrawl Lanoxin 50 mg tramadol Genric viagra Dulcolax Phentermine abuse Phentermine no prescription Buy phentermine fedex Viagra sale uk Cheapest viagra in uk 30mg phentermine Kanamycin Phencyclidine Triprolidine Cefamandole Viagra side effects Nitroprusside Albuterol Phentermine $89 Cardizem Flutamide Buying xanax Phentermine pillstore Viagra patent expiration About phentermine Tramadol hcl 50mg Prempro Mexican pharmacies online+no precription xanax Cash on delivery phentermine Tamoxifen Pictures of xanax pills Phentermine cash on delivery accepted Carbamazepine Isosorbide Cheap 37 5 phentermine Minocycline Cheap cialis generic Buy phentermine online with pay pal Phentermine no rx needed Melphalan How long does xanax stay in the system Cialis western open Ketamine Viagra cialis generic Promazine Viagra like pill Xanax dosing Discount viagra perscription drug Diphenhydramine Phentermine success stories Phentermine cheap Benadryl Cod online pharmacy phentermine sell Clorazepate Buy Cialis Phentermine without rx Order soma online Drug loss phentermine weight Vidarabine Urokinase Phentermine adipex Blindness cialis Buy viagra on line Discount phentermine to florida Omnicef Buy online viagra where Buy phentermine online cod Viagra pill splitter Nitroglycerin and viagra Amaryl 0 buy by popl powered viagra wordpress Phentermine yellow 30 mg Loprox Free shipping on phentermine diet pills Lose weight with phentermine and 5 htp Approval cialis Quinacrine Long term phentermine use Zalcitabine Discount hydrocodone Amaryl Cheapest viagra online Ionamin phentermine Norfloxacin Drug screening phentermine Xanax drug tests Quinidine Phentermine online without prescription Electricity Ergocalciferol Flurazepam Order generic cialis Aldara Phentermine order Tramadol hcl 50 mg Phentermine resin Viagra testimonials Phentermine 30mg Nizatidine Clozapine Fluphenazine Pictures of mylan xanax Dipyridamole Hydrocodone m358 Cialis effective soft tab treatment Locoid Fenoterol Online viagra sales Cheap overnight tramadol Viagrafix Aprotinin Fastin Ambien prescription Ethinyl Meridia order Hydrocodone drug Texas personal injury lawyers viagra Anti cialis impotence Filing income tax phentermine Phentermine pharmacies Geodon Ativan xanax Phentermine meridia xenical review Buy levivia viagra Amoxicillin Order phentermine c o d Xanax no rx Gatifloxacin Amlodipine Buy free phentermine shipping Piperacillin Compare viagra to cialis Encainide Viagra generico impotencia Permax Overnight viagra Phentermine hydrochloride ship to missouri Cyclopenthiazide Allopurinol Compare viagra cialis levivia Meridia diet Buy cheap no phentermine prescription Buy in online uk viagra Viagra commercial Phentermine prescription Buy Didrex Phentermine in jonesboro arkansas Phentermine with no prescription Cyproheptadine Desyrel Cod phentermine shipped Buy phentermine online same day delivery Potassium Vitamin Finasteride Avalide Alprazolam Viagra on line Taking viagra or levivia as a booster for cialis Xanax online overnight Lethal doses klonopin wellbrutrin xanax Phentermine reviews Buy consultation free hydrocodone online tramadol Nicotrol Phentermine uk Diet pill xanax Buy Cialis Tramadol avinza drug interaction Amphetamine Prescription viagra written Pediacare Phentermine versus meridia Methotrimeprazine Pharmacy phentermine affiliate Fioricet online Probenecid Different types of phentermine Viagra soft tabs Ativan re valium vs vs xanax Aricept Mepenzolate Viagra uk Non prescription phentermine Cheap soma Buy cheap no phentermine prescription Generic name viagra Phentermine pharmacy online consultation Cheap viagra order online Viagrafix Phentermine sameday overnight saturday delivery Viagra levivia Xanax withdrawl message boards Iodipamide Flexeril Generic fioricet Phentermine hcl Nelfinavir Mechlorethamine Furazolidone Taking viagra or levitra as a booster for cialis Acarbose Tussionex Acetophenazine Indocin Senna Viagra alternative for women Zafirlukast Free phentermine sample Nicardipine Fluvoxamine Xanax for dogs Clidinium Lowest cost phentermine Cialis tadalafil Phentermine alternatives Xanax american express Viagra cheap Loperamide Female spray viagra Nasalcrom Buy online viagra Spiramycin No fax payday loan buy tramadol Actos phentermine aciphex imitrex Tramadol long term use Eulexin Viagra side affects Buy viagra online uk Online pharmacies with doctor consultation for viagra Long term phentermine use Senna Cheap cialis Phentermine success stories Elidel Phenacetin Viagra class action Discount cialis online Cialis forum Doxycycline Natural suppliments work like viagra Diet loss phentermine pill weight Phentermine guaranteed overnight shipping Hytrin Buy Famvir Cope 1 loss phentermine pill weight Cheapest cialis Ambien eminem Cialis for sale uk Phentermine 37.5 tablet Vicodin Drug screening phentermine Mephobarbital Tramadol online pharmacy Carvedilol Cafergot Cialis and levitra Hydrocodone addiction Cialis drug impotence Free viagra without a perscription Order tramadol Phensuximide Dexchlorpheniramine Nadroparin Urine drug testing of tramadol Phentermine law suits Viagra canada Deslanoside Protamine Buy Renova Sotalol Ephedrine Diet pill phentermine Ditropan Discount phentermine no prescription Generic viagra soft tab Accutane Amoxil Xanax valium Mobic Troglitazone Zestoretic Feldene Ionamin Cheap phentermine Elocon Phentermine in florida Adipex phentermine prescription 120 cheap tramadol Aminophylline Ephedrine Metaraminol Phentermine buy online Phentermine np Cause rebound weight gain phentermine Erythromycin Cefixime Best online deal for phentermine Hydrocodone cod only Cialis vs viagra Buy viagra Cialis compared to viagra Recreational viagra Prazosin Ambien prescription Enalapril Phentermine work Cortisone Xanax online prescription Pargyline Estrace Colestipol Zetia Cheap phentermine online 37 5 Online xanax Tramadol 50mg Cialis tablet Fluvastatin Cosopt Berman sister female viagra study Bontril phentermine adipex Discount online viagra Buy cheap phentermine cod Phentermine weight loss Buy generic phentermine Pentasa Losartan Prempro Danazol Drug information picture identification tramadol er bvf Premarin Ketoprofen Cheap xanax no prescription Xanax drug testing Phentermine ups shipped Cetirizine Phentermine 37.5 mg no prescription Phentermine works Saquinavir Levivia viagra vs Prozac drug interaction with xanax Xanax weight gain Maxzide Over the counter viagra Viagra cialis generic Troglitazone How to use viagra Xanax paypal Betaxolol Cheap phentermine 37.5 mg Cheapest viagra in uk Epo Xanax effect Phentermine hcl side effects Phentermine blue Levothyroxine 5 mg Viagra commercial Nicoumalone Phentermine eprescriptions Dipyridamole Diet information phentermine pill Nasonex Advair Cheap tramadol online Lortab and xanax without a prescription Levlen Gabapentin Tramadol withdrawal symptoms Cheep paris france phentermine Clofibrate Nadolol Nicorette Tramadol and dosage Phentermine mastercard Nystatin Which is better cialis or levitra Difference between cialis and viagra Echothiophate Azithromycin Phentermine very cheap Eldepryl Cialis mexico Xanax doseage Woman using viagra Hexoprenaline Herbal online viagra Trovafloxacin Dilaudid Midazolam Keyword tramadol Xanax photo Allegra Nutmeg Hydrocodone bitartrate acetaminophen Buy ambien Book hydrocodone sport Diltiazem Orlistat Viagra info Cipro Methimazole Trazodone Buy xanax online Vicodin m360 37 effects phentermine side Nicotrol Ethanol Cycloserine Cialis levivia sales viagra Phentermine online ordering Drug interaction sibutramine and phentermine Prilosec Buy Diazepam University rochester viagra pfizer Olanzapine Lescol Adapalene Mexican pharmacy phentermine Amoxil Tramadol dog Lowest price viagra Alavert Cilostazol Natural alternatives to viagra Hydrochlorothiazide Soma carisoprodol Order soma online Xanax prescriptions Phentermine diet drug Viagra prescription Phentermine no prescription required next day delivery Methyclothiazide Remeron Hydralazine Hydrocodone com Trandolapril Cialis immunity Enoxacin Cefdinir Estrone Moxifloxacin Xanax sale How long does phentermine stay in your system Cyclobenzaprine Phentermine pharmacys online Adipex cheap phentermine Cialis online Thyroid Dutasteride Tramadol overnight Buy cheap tramadol Viagra price Buy phentermine online cheap Phentermine 37.5mg tablet Phenobarbital Xanax withdrawel Xanax grapefruit juice Generic viagra fast shipping Viagra Temazepam Add a link viagra Information about street drugs or xanax bars Lopid Viagra cialis generic Pfizer xanax information On line prescription viagra Buy phentermine prescription Sample viagra Birth defects and phentermine use Fiorinal Buy generic online phentermine Xanax overnight Cheapest phentermine diet pills Cod overnight tramadol Phentermine sameday overnight saturday delivery Phentermine and birth defects Viagra faq Phentermine no fees Sulfonamides Addicted to xanax Cheap phentermine online withour prescription Tramadol side effects Buy Alprazolam Phentermine forums Trimetrexate Cefixime Phentermine with hoodia Diet phentermine pill Buy viagra without a prescription Mexican pharmacy phentermine Xanax cod Xanax uses Get viagra online Lanoxin Codeine Order xanax on line Levivia vs viagra Soft tab viagra Rabeprazole Buy phentermine online with pay pal Buy viagra 1 Colace Ranitidine Stavudine Uk viagra body building from sports supplement Lotrimin Cyber pharmacy phentermine History of phentermine use Compare viagra cialis levitra Fosinopril How does viagra work 5 free shipping Herbal alternative viagra Phentermine online consultation Pictures of xanax bars Buy generic phentermine Purchase tramadol without a prescription Disulfiram Tramadol cheap Phentermine pill town Macrodantin Buy Adderall Dovonex Buy phentermine yellow Perindopril Cialis drug prescription Buprenorphine Itraconazole Where to buy viagra Phentermine forum Biaxin Diet diet dieting phentermine pill Scopolamine How do i stop taking phentermine Detection drug in phentermine screen urine Actos Synthroid Cheapest viagra uk Citalopram Viagra doseage Discount viagra Buy Lorazepam Cheap phentermine online no prescription Cheap cialis generic Cilostazol Phentermine usa Fioricet description Constipation phentermine Paxil with phentermine interactions Ambien Aciphex Cheap overnight phentermine Cheap phentermine without a prescription Phentermine cash on delivery accepted Tramadol online cheap Accutane Line pharmacy phentermine Itraconazole Clomipramine Phentermine prozac Liothyronine Rated online pharmacies for phentermine Miconazole Generic price viagra Natural viagra free samples Sildenafil Phentermine tablet Canada cialis generic Cinnarizine Clarithromycin Deslanoside Per day buy phentermine Buy Propecia Lowest cost phentermine guarantee free shipping Diet ky phentermine pill ship that Xanax effect Kevin harvick viagra Phentermine very cheap Free viagra without prescription Generic tramadol Tramadol prescriptions Leflunomide Phentermine lowest price Long term effects of phentermine use Xanax addiction Xanax and drug testing Buy phentermine epharmacist Purchase xanax online Metoclopramide Pfizer viagra sperm Blindness viagra Is it safe to take prozac and phentermine Xanax withdrawal symptoms Clarithromycin Cialis levitra sales viagra Repaglinide Meridia online Hydrochlorothiazide Dacarbazine Compare cialis levitra viagra Online viagra prescriptions Which is better cialis or levitra Mexican pharmacy viagra Do companies sell phentermine with low dose ingredients Morphine Fluorescein Hydrocodone ap ap Buy phentermine in canada Addiction recovery xanax Lexapro and phentermine Mazindol Vicodin for sale Tramadol hci Phentermine online purchase Information phentermine Flexeril Chlortrimeton Phentermine gynecomastia Pantothenic Alesse Afrin Viagra and high blood pressure Phentermine side effects Phentermine feedback Phentermine no prescription needed Xanax prescription Cefonicid Foradil 25mg viagra Cialis tablets Accupril Cialis price compare Luxury hotel rome xanax description Claritin Free cialis Cheap phentermine perscription Tramadol overdose Info on meridia Adalat Does phentermine really work Caffeine Ordering 30mg phentermine Colistimethate Generic viagra cialis levivia buy cheap Buy online prescription viagra Cialis company

Information and Links

Join the fray by commenting, tracking what others have to say, or linking to it from your blog.


Other Posts
So, what now?
FB == C++?

An Introduction to Inline Assembly and Registers

Posted by Unknown on August 15th, 2006

Without much dispute, FreeBASIC is one of the most powerfull BASIC compilers created to date. With the combination of its standard BASIC features to its advance features, (pointers, C/C++ library support, etc…) FreeBASIC supplies its users with the familiarity of classic BASIC, but ability beyond what BASIC users have experienced. However, even with FreeBASIC’s array of potent features, few of its users have ever embraced its most powerful feature, ‘Inline Assembly’.

Assembly is the first PC programming language. It is considered “low-level”, because it’s functionality and syntax is greatly dependant on the target system’s architecture. Whereas BASIC is considered “high-level”, because it’s functionality and syntax is designed to remain consistent despite its targeted system’s architecture. The advantage of high-level languages is their syntax and grammar greater resembles that of spoken languages. The greatest advantage of low-level languages is their speed. However, low-level languages, (such as Assembly) hardly resemble spoken languages. For this reason, they are often intimidating to even the more experienced programmers. Fortunately, programming FreeBASIC’s inline assembly is notably simpler than programming Assembly alone.

To inform FreeBASIC that a line of code is written in Assembly, it must be preceded by the keyword Asm. Such as:

Asm ...

If more than one line of Assembly is being used, it can be included with an Asm block:

Asm
...
End Asm

Keep in mind, all variables and procedures declared previous to the Asm statement or block are accessible by the Asmstatement or block. Which will be demonstrated.

As with any language, one of Assembly’s fundamentals is data transferring. However, in Assembly, data can never be transferred directly from one memory location to another. It must first be transferred to hardware-embedded variables known as registers. These ‘variables’ are Intel created. These registers have varying sizes, that range from 8bit to 32bit. The 8bit registers include AL, AH, BL, BH, CL, CH, DL, DH. The 16bit registers are AX, BX, CX, DX, BP, SP, DI, SI. Lastly, the 32bit registers consist of EAX, EBX, ECX, EDX, EBP, ESP, EDI, ESI. Each of these registers, (or hardware-embedded variables) serve specific purposes during certain circumstances. To avoid confusion their situation-specific purposes will be mentioned only when necessary.

In order to store data within any register, the chosen register’s size must be equal or greater than that of the data. For instance, an 8bit register can not hold 32bits of data, but a 32-bit register can, logically, hold 8 bits of data. To transfer data, one would use the Mov command, (also know as a “mnemonic” in Assembly). Its format is:

Mov SizeOverride Operand1, Operand2

SizeOverride is not required, but if included specifies the amount of data being transferred. The possible size overrides are:

  • Byte (move 8 bits)
  • Word (move 16 bits)
  • DWord (move 32 bits, or a Single)
  • QWord (move 64 bits, or a Double)

Both Operand1 and Operand2 can either be registers, immediate data, or memory locations. Immediate data is either a literal number, (such as 5 or 3), or a FreeBASIC variable’s name. How to specify memory locations will be covered shortly. There are certain criteria when transferring data that must be satisfied:

  • Operand1 is always the destination of the moved data
  • Operand2 is always the source of the moved data
  • both Operand1 and Operand2 can be registers, (even the same register) but both registers must be of the same size
  • Operand1 can never be immediate data
  • Operand1 and Operand2 can not both be memory locations

A memory location is specified by simply including a register, certain combinations of registers, immediate data, or a combination of these within braces ([ ]). The only registers that can be used to specify a memory location on their own or in combination with immediate data include BX, SI, DI, EAX, EBX, ECX, EDX, EBP, ESI, EDI. However, the following pairs of registers can be used to specify a memory location by themselves or with immediate data:

  • BX+SI
  • BX+DI
  • BP+SI
  • BP+DI

In the case of a pair of registers the sum, (and only the sum) of the specified registers’ values will determine the memory location. To better understand data transferring let us study the various scenarios. Throughout these examples various registers will be used. For simplicity’s sake, assume these registers’s values have been preset as necessary. Suppose we need to move data from one register to another.

Asm Mov BL, AL

Now the register BL contains the same data as that of AL. Remember, when transferring data amongst registers both registers must be the same size. Now, let us see how to move the contents of a register to the memory location indicated by the register EAX:

Asm Mov [EAX], AL

When a register’s data is being transferred to memory, the register’s size dictates how much memory is effected. Also, notice that the registers’ sizes do not match. This is permitted, because the contents of register AL are not being transferred to register EAX, but rather to the memory location specified by EAX. Now, study this example:

Mov [BX+SI], AL

This example is quite similar to the previous. In this example though, the contents of register AL are stored at the memory location indicated by the sum of the registers BX and SI. Any of the valid pairs of registers previously mentioned may be used. These were randomly chosen solely for example. A register’s data can even be stored in a variable. Let us assume there is a FreeBASIC variable named Number, of data type Long (32-bit), that has the value 5 and that register CL contains the value 10.

Dim Number As Long = 5
Asm Mov [Number], CL

The intention would be to store the value 10 in the variable Number. Keep in mind, though, when transferring data from a register to memory the register’s size dictates how much memory is stored and effected. In this example the contents of register CL is stored in the variable Number. However, since Number is 32 bits and CL is 16 bits only half of Number is altered. This can cause different results than expected. To ensure that the appropriate value is stored in Number, use a register of the same size. Let us now assume ECX contains the value 10.

Asm Mov [Number], ECX

Now, since both Number and register ECX are 32-bit, all of Number is effected and the expected outcome of this statement would be accurate. The variable Number now holds the value 10. One can use a literal number to specify a memory location. Such as:

Asm Mov [012345], ECX

However, this can be dangerous. Remember, the operating system and other software are using memory as well. Altering their reserved memory can have unpredictable results. Let us now view how to transfer data from memory to a register.

Asm Mov ECX, [BX+SI]

By default, The register’s size determines the amount of data that will be transferred to it. Therefore, in this example, 32 bits, (from the memory location indicated by the sum of registers BX and SI) are stored in register ECX. To ensure that a certain number of bytes is transferred use a size-override.

Asm Mov Word ECX, [BX+SI]

Now 16 bits of data would be transferred from the specified memory location to the chosen register. However, 16 bits is only half of register EAX’s size. The outcome of this statement may still not be as predicted.

Asm Mov DWord ECX, [BX+SI]

In this example 32 bits of data would be transferred from the specified memory location to register ECX. Since the register’s size and the size of data being stored into the register are the same this statements outcome would be accurate. Of course, a variable’s data can be transferred to a register as well. Let us assume, again, there is a FreeBASIC variable named Number, of data type Long, that has the value 5.

Dim Number As Long = 5
Asm Mov ECX, [Number]

Register ECX would now contain the value 5. Now, assume there is a variable named Number, of data type Double, that has the value 5.1234 . Since variables of data type Double are 64 bits in size, and none of the registers mentioned are 64 bits, one could not transfer the contents of a variable of data type double to any of the mentioned registers. However, the address of a variable of data type Double could, indeed, be stored into a 32-bit register. Although mathematics (both integer and floating-point) will not be discussed as of yet, this is important to remember when the subject is discussed.

Dim Number As Double = 5.1234
Dim Adr As Long = @Number
Asm Mov EAX, [Adr]

Register EAX now contains the address of the FreeBASIC variable Number. Notice the use of a 32-bit register. Obviously, 32-bit operating systems use 32-bit addresses. Using a 32-bit register ensures the whole address is stored. The case of variables of data type String is similar. Since strings can be of virtually any size, only a string’s address should be stored in a 32-bit register. Such as:

Dim MyString As String = "some text"
Dim Adr As Long = StrPtr(MyString)
Asm Mov EAX, [Adr]

Notice that the FreeBASIC function StrPtr was used to retrieve the string’s address. This is because strings in FreeBASIC include headers, (or ‘descriptors’). To retrieve the actually location of the string’s characters, StrPtr must be used.

This concludes general data transferring using FreeBASIC’s inline Assembly. With this knowledge, one is prepared for Integer Mathematics using inline Assembly. Which will be discussed in the next lesson of this tutorial.



Write a Comment

Take a moment to comment and tell us what you think. Some basic HTML is allowed for formatting.

You must be logged in to post a comment.

Reader Comments