You are here: ApiroTech > Programming > Programming

 
 
 

Programming

PREVIOUS     NEXT

C++: Differences between C++ and C#

 Key differences between C# and C++It was a surprise that there was no thread for C++ recipes. Though C++ and C# are quite similar there are some very key and major differences. -I find C# resembles the style of java more than that of C++ i many ways. (I will be following this up with some coding recipes, to hopefully start a C++ reciped thread) Method/Function Declarations: C++: public: Constructor() { } void aMemberFunction() { } void aFunctionDeclaration(); private: void someOtherFunction() { } int aVariable; C#: private aVariable; public void aMemberFunction() { } public void aFunctionDeclaration(); private void someOtherFunction() { } Class Declaration: For those who know what a managed class is: C++: __gc class A_Class{ }; *NOTE that C++ classes end with a ; C#: automatically done so: class A_Class{ } Inheritence: C++: will allow multiple inheritence. eg. allows a method to be overriden many times in subclasses (derived classes). C#: supports inheritence, but not multiple, only 1 ... Read More

C++: Main Operator Overloading

 How to Overload the common operators: =, +, -, *Overloading an operator allows for custom operations on your own objects. *Say you want to add to person objects (ex. marriage)? -then you overload the + operator and define what is to be done when you add the objects. *For all my examples i will be using Person as the class which is my personally defined object. + Operator: The + operator takes 2 operands if it is declared outside of the Person class: //+Operator Overloader Person& operator+(const Person& p1, const Person& p2){    //code goes goes in here } The + operator takes 1 operand if it is declared inside the Person class: //+Operator Overloader Person& operator+(const Person& p2){    //code goes goes in here } *The object p1 can be accesed as a pointer as well with the keyword this. - Operator: The - operator takes 2 operands if it is declared outside of the Person class: //-Operator Overloader Person& operator-(const Pe... Read More

C++: Operator Overloading (slightly more complex)

 How to Overload the operators: ++(int), (int)++, --(int), (int)--The key is to know the action of these operators on the integers they are supplied for: For coding examples i will again be using Person as my example class. Perhaps ++ or -- increments or decrements the number of friends a particular person has. ex: int i = 0; ++i = 1; i++ = 1; //result is old value i = 2; //next time i is used, reveals the new value --i = 1; i-- = 1; result is still old value i = 0; //next time i is used, reveals the new value No parameters are supplied in either case the prefix versions are straight forward: Prefix ++ | ++(int): //++Operator Overloader - prefix    Person& operator++(){    this->friends = this->friends+1; //assuming Person class has a field friends.    return *this; return in the case of an assignment as well } Prefix -- | --(int): //--Operator Overloader - prefix    Person& operator--(){    this->... Read More

C++: Operator Overloading (even a little more complex)

 How to Overload the operators: +=, -=, *=, /=, %=Very similar to overloading the +,-,* operators within a class, as they all take a single parameter as such: As with all the other Person will be the custom class. Perhaps these operations combine the friends of 2 people to the friends of one of the persons. += Operator: Person& operator+=(const Person& p1){      this->friends = this->friends + p1.friends;      return *this; } -= Operator: Person& operator-=(const Person& p1){      this->friends = this->friends - p1.friends;      return *this; } *= Operator: Person& operator*=(const Person& p1){      this->friends = this->friends * p1.friends;      return *this; } /= Operator: Person& operator/=(const Person& p1){      this->friends = this->friends / p1.friends;      return *this;... Read More

Assembly: The Registers and Segments (MASM/TASM)

 The name and type of the registers and segments usable by a 32-bit processor (Easily converted by a naming convention to 16-bit and even 64-bit)Since there are no other recipes on Assembly Language, it would be irrational to start anywhere but the basics of hardware in assembly programming. I myself do not use a Pentium Processor, but since the assembler i am writting for is specific to Pentium some names may be off. When using MASM or TASM the naming conventions will work no matter the Processor you have as long as it is in the corresponding size (eg. 32-bit, 64-bit etc) The Registers: Visual Representation: --------------------------------------------- |11111111111111111111|22222222222|3333333333| --------------------------------------------- This applies to EAX, EBX, ECX and EDX: *EAX will be the example -The entire register (32-bits) containing 1's 2's and 3's is EAX -The section filled with 1's is the upper or left 16-bits of EAX, which cannot be accessed directly -The other half ... Read More

Assembly: Flags

 The EFlags register, what they, what they do and when they are set.The flags are located in a single 32-bit register (EFlags), each a single bit, thus holding a value of 1 true, or 0 false. I will list the flags by name, location in the register and use: *location will be a bit from 0-31 00: CF Carry Flag - becomes one if an addition, multiplication, AND, OR, etc results in a value larger than the register meant for the result 02: PF Parity Flag - becomes 1 if the lower 8-bits of an operation contains an even number of 1 bits 04: AF Auxiliary Flag - Set on a carry or borrow to the value of the loer order 4 bits 06: ZF Zero Flag - becomes 1 if an operation results in a 0 writeback, or 0 register 07: SF Sign Flag - is 1 if the value saved is negative, 0 for positive 08: TF Trap Flag - allows for the stopping of code within a segment (allows for single stepping/debugging in programming) 09: IF Interrupt Flag - when this flag is set, the processor begins 'listening' for external interupts ... Read More

Assembly: Code Template

 The general template for designing an Assembly code program TITLE    COMMENT |         | .MODEL SMALL .STACK 100H .DATA .CODE .486 INCLUDE io.mac main    PROC         .STARTUP done:         .EXIT main    ENDP         END   main -after title commonly listed is the name of the current file possibly including the path -placed between the | | are comments describing the program -model type SMALL describes code which only points within it's own scope, or uses extern with path names. -under .DATA goes your pre-defined terms, such as global variables and strings to be output -under .CODE goes the actual code of your program -.486 describes the type of program, if you wish to include ONLY 8086 type you may also choose .386 -the include here allows for read and write of IO properties from the keyboard (standard IO) -main is only a standard name, it can be any name .STARTUP... Read More

Assembly: If (MASM/TASM)

 How to implement the in assembly, the effect of the if statement, which is available to other languages.Being that Assembly is a low level language, as opposed to the high level most programmers are used to (eg: Java, C, C++, Perl, etc), it doesn't have all the same features that these languages have.. like an if statement, but it can be implemented in a more baic way. assembly language runs top down, from label to label through the main of the program, only varying upon jumps etc (described in full later), we can take advantage of this to implement our if. Example: .MODEL SMALL .STACK 100H .DATA result_msg   DB  'true inside if statement',0 .486 .CODE INCLUDE io.mac main    PROC         .STARTUP start_go:     mov Ax,0     cmp Ax,0     jne done     putStr result_msg     done:         .EXIT main    ENDP         END   main The ... Read More

Assembly: mov statment (MASM/TASM)

 How to use movmov is a useful tool in assembly language, it can move constants, or dynamics such as offsets. mov takes 2 parameters, the first is the reciever and the second is the operand. Example: mov AX, 5 ;this places the value 5 into AX register mov BX, OFFSET array ;this would put the offset of the variable array into BX Questions/Comments: william_a_wilson@hotmai.com -William. (marvin_gohan)... Read More

Assembly: constant jmp statment (MASM/TASM)

 How to use jmpjmp used as a jump statement jumps from one place to another: Example: .MODEL SMALL .STACK 100H .DATA result_msg   DB  'true inside if statement',0 test_msg      DB  'no jmp',0 .486 .CODE INCLUDE io.mac main    PROC         .STARTUP start_go:     putStr test_msg     jmp done     mov Ax,0     putStr test_msg     cmp Ax,0     jne done     putStr test_msg     putStr test_msg     done:     putStr test_msg         .EXIT main    ENDP         END   main all of the code in this program is passed over by this jmp command, try moving it to different places to prove that it is a static jump, and all code between the jump and target (in this case the tag done) is skipped. Questions/Comments: william_a_wilson@hotmai.com -William. (marvin_gohan)... Read More

Assembly: conditional jmp statments (MASM/TASM)

 How to use the conditional jmp, jumps (je, jg, jl, jne, etc)a conditional jump, is just that, it jumps on a condition, if the condition is false, then if continues with the next line. eg: cmp 0,1 je one_equals_0 mov AX,0 if je returns true... which it won't (this code shouldn't work at all actually) then the mov statement is run, if it had returned true, then transfer of control would be moved to one_equals_0 label, where ever that is. Arithmetic Jumps: je - jump if equal, takes 2 parameters jne - jump if not equal, takes 2 parameters jl - jump if less than, if second parameter is less than the first jg - jump if greater than, if second parameter is larger than the first *NOTE there are many othe jmps available as well, some redundant, or uncommon. Flag Jumps: jz - jump if the last cmp or operation set the zero flag jnz - jump if result is not zero *Truthfully it is a flag or combination of flags that determines if the jump is taken or not in every case. you can combine nearly any jump... Read More

Assembly: Define Directives

 The size and reason for defining different sized parameters [b]DB:[/b] Define Byte        ;allocates 1 byte [b]DW:[/b] Define Word        ;allocates 2 bytes [b]DD:[/b] Define Doubleword  ;allocates 4 bytes [b]DQ:[/b] Define Quadword    ;allocates 8 bytes [b]DT:[/b] Define Ten bytes   ;allocates 10 bytes Keep in mind that assembly does not actually care about words but rather the number of bytes. To define a string DW is used, to ensure enough space is reserved (though space is not reserved the same way as it is in high level languages) These directives would be used to declare variables in the following manner, in the .DATA section of your program. sorted    DB   y empty     DB    ?           ;no initialization number    DW   2515... Read More

Assembly: DUP command (MASM/TASM)

 how to use the DUP - duplicate command, nested or un-nestedAs it sounds, DUP duplicates text. Straight Example: text   DB  10 DUP (W)  ;initializes 20 bytes to W the number after DB defines how many bytes to repeat for, and then the 'W' defines what to repeat. Nested: barCode DB 4 DUP(3 DUP (l),2 DUP (|),5 DUP (I)) reserves 40 bytes in total, initialized to: lll||IIIIIlll||IIIIIlll||IIIIIlll||IIIII each pass through creates lll||IIIII then this is repeated 4 times as it is nested within another DUP command. Questions/Comments: william_a_wilson@hotmail.com -William. (marvin_gohan)... Read More

JavaScript: password protection

 how to password protect a webpage with javascript (the password is not viewable in the source of the page)If someone REALLY knows what they are doing, it is impossible to prevent all access with javascript, but here's a way to keep those wannabe hackers from seeing your password in the source of you protected page. to fully take advantage of this feature you will need Unix/Linux permission knowledge or a program such as cuteFTP to change the attributes of our script file. *Scripts are not allowed on this site, so replace * with inside the code blocks! first we need a page to display the password prompt. Using a simple form and action to call our eventual script is all that is necessary. *This can be expanded to include usernames etc. *html$ *head$    *script src="scripts/pass.js" type="text/javascript"$*/script$ */head$ *body onLoad="top.window.focus()" BACKGROUND="images/code.jpg"$ *center$ *br$ *h1$Restricted Area: Site Ad... Read More

Assembly: arrays

 How to create and traverse an array in assembly languageAssembly doesn't care what your variable is, it only cares how many bytes it needs. creating and traversing an array is thus a little confusing, but very simple as long as each element is the same size. This example is well commented and creates and the displays a 20 element array of integers. *NOTE that the example loads the array, then displays it backwards, if you wish to display it forward, load the offset of array into BX again, and add 4 instead of subtracting it. TITLE       ARRAYS          ARRAYS.ASM COMMENT |         Creates an array and traverses it, printing the values | .MODEL SMALL .STACK 100H .DATA array           DD  20 DUP (?)  ;80 bytes total or 20 4 byte Long Integers .CODE .486 INCLUDE io.mac main PROC .STARTUP     mov     BX,OFFSET array ;get start of array (array[0&#... Read More

Flash / Actionscript: Create an Array of Objects from a Unique Class

 When starting in AS2, I found it difficult to make an array of objects after creating my own class. Hopefully, this little tutorial will make it easier for others.I spent 8 hours trying to figure this out initially. To me actionscript handles this a little differently than other programming languages. Basically we will create a small class, create an object with that class, and then load that object into an array. First we create our class. Remember to create a class, you have to do it from a seperate actionscript file. //in testclass.as class testClass {     //Establishes the first variable in your testClass    public var first: String; } Now, here is the heavily commented code that should be in your main actionscript file. //Import your unique class--testClass import testClass; //create tC object from your test class //create an array to hold the objects var theArray:Array = new Array(); //create loop with i as the counter for (var i=... Read More

Flash/Actionscript Basics: If - Then - Else Statement Syntax

 Creating a basic if - then statement in flash or actionscript is easy. Here is the correct syntax. The basic syntax is the following: if (condition) { statement(s); } Here is an actual working example. If the variable userInput contains data, the value will be sent to the trace command. if (userInput != undefined) {    trace("Input is " + userInput); } Adding an else section is not much harder: if (userInput != undefined) {    trace("Input is " + userInput); } else {    trace("Input is unknown" ); }... Read More

Assembly: division

 How to divide large numbers with assembly language, and where the results end up.numbers are most commonly divided by smaller numbers (eg a 16 bit number divided by an 8 bit number) The numerator must be placed in specific registers and the denomenator is supplied as a single operand. This example takes a possible 32 bit number and shows how to move it's contents to the correct 16 bit registers. XOR     EDX,EDX ;clear EDX ;place number to be divided into EDX (32-bit) XOR     CX,CX ;clear CX ;place 16-bit denomenator into CX do_division: mov     AX,DX       ;move least significant bits to AX shr       EDX,16      ;shift most significant bits to DX div       CX            ;divide DX:AX by CX ;quotient in AX ;remainder in DX that's all there is to it. 16 bit numbers are of course easier to deal with as there is no bit shiftin... Read More

Assembly: Bit Shifting

 Shift bits left or right by a desired numebr of places Bit shifting is an easy task. Shift left (in this case by 8): shl EAX,8 or to Shift right (in this case by 8): shr EAX,8 you simply provide the 2 operands: 1) the register to shift 2) the number of places to shift This method will autmoatically fill the slots without data as 0. Questions/Comments: william_a_wilson@hotmail.com -William. (marvin_gohan)... Read More

Assembly: Bit Rotating

 Shift bits left or right by a desired numebr of places, with a wrap around to the other sideThis method saves all bits. Say you shifted AX by 8, in either direction the new AX value would hold AH as the old AL and AL would become the old AH. This is done with a temporary copy of the register which is then shifted into the blank slots as the shift occurs. Shift left (in this case by 8): shld AX,8 or to Shift right (in this case by 8): shrd AX,8 you simply provide the 2 operands: 1) the register to shift 2) the number of places to shift Questions/Comments: william_a_wilson@hotmail.com -William. (marvin_gohan)... Read More

 

 

Pages : 1 2