UPL

UPL : “Universal Programming Language“, or you can say UPL : “UPL is Programming Language:) .

It is an idea that we were thinking of for more than a year, and thanks to Yamani it is slowly coming to the reality.

The Idea
As was discussed in many blogs few weeks ago, we need to find good and intelligent ways to teach our children and “programming children” (those who are not Childs in real but newbie in programming world) about programming.

Thinking about that we can see (as we think) the two biggest obstacles faced by these two groups are:
(1) The complex syntax:
come on how many people you know were able to understand the pointer of pointer of a function that takes a reference and a pointer in C++ from the first time :) .
(2) The Language:
by language we do not mean the programming language but the “English” language (even though it is becoming the universal language now, still lots of kids have problems in English learning it. (and come on who said programming must be in “English”).

What UPL can do about that!
Well so what do UPL do exactly?
It is not the direct solution to the problem, but it is one of the keys to the solution. It is a simple engine where you can create your own programming language with your own syntax, and with the human language that you desire.

The current version of UPL support a very simple syntax that is some how look like old quick basic. There is a language file where you can replace any keyword in the (English UPL) to any other keyword in any other language or any other word in English itself , for example the keyword “Declare” could be changed to “dim” to look like visual basic more, or it can be changed to “Aref” the Arabic word the means declare, or even you can write in Arabic writing, French , Japanese, and like that it gives endless choices of creating your own language.

What happens inside the upl Editor is what ever syntax you are using it will be translated to the English up and then again the English upl is translated into JAVA (in the current version the algorithim is updated to change any syntax to Java directly) and finally java file is produced compiled and executed.

the syntax of current English UPL is very simple:



download

UPL in action(Future)
Well yes it is not in action yet (well it is still alpha, still it don’t have loops,still … , ….,….) but lets talk about future , what UPL can do when it gets into action. So lets see some possible futures for upl:
1- Engine for creating lots of educational programming language syntax in different human language scripts (English , French, japanease, ….).

2- The same engine mentioned before could be use to make programming look more like story writing for kids
(I mean after a lot of modifications) a kid will be able to write some kind of story and clicking on run will show him the story happening infront of him ( well we will need to use graphical libraries for doing so).

3- Visual animated programming ( ummm imagine this )
: a kid opens a software he drags an icon of a hummer with declare written on it then he writes “x=12” , next he will drag an icon of wondering rabbit that have if written between it ears and write “x>10”, and continue programming in this way. We can see this drag and drop will create may be html document, and there will be a translation file from that kind of html into the English upl which will be automatically translated to java and run.

Read More

Assembly Language – Shift Instructions

If you tried to search sites for advanced assembly language tutorials (Intel architecture). you will find that the number of the useful sites is relatively little compared to the other programming languages . therefore, and due to the lack of advanced assembly language tutorials, i am willing to share my humble knowledge in assembly programming with you all.

if you are not familiar with the term “Assembly Language Instructions”, this post is not for you. this post is dedicated to the people who already know the simple instructions of assembly language and want to know more advanced instructions in assembly language.

In this post i will explain the “Shift Instructions” ien Assembly Language, how to use it and finally the practical uses of those instructions.

i will explain the shift instructions for Unsigned binary numbers here.


Explaining Shift Instructions:

Shift Instructions in assembly language is used to shift the most significant bit (MSB) or the least significant bit (LSB) in binary number (in a register or a variable).

Now you might ask, what is shifting??
for example if we have a binary number (e.g. 1111 0000)
using the shift instruction we can make 2 decisions:
1- if we choose to shift that binary number to the left by one bit the outcome will be (1110 0000)
2- if we choose to shift that binary number to the right by one bit the outcome will be (0111 1000)

Now you might ask another question, where did the (MSB) go? and what happened to the (LSB)?
well, in the first case the (left shifting) (MSB) (which is “one” in this case) went to some kind of temporary location called C-Flag (Carry-Flag), and an additional “zero” have been added to the right of the binary number and has become the new (LSB).

the same goes with the second case (right shifting), we took the (LSB) and put it in the C-Flag and then we added a “zero” to the left hence, the new (MSB) is “zero”.

you can imagine the C-flag as a Box, whenever you remove a bit from a binary number you put that bit in that box before you throw it a way!

Code Explaination for Shift Instructions:

i am sure that all programmers now are saying “WTH does that mean??”.
i am also a programmer and i understand codes better then plain English!!! so, if you didnt understand what i wrote about the shift instruction previously, i am sure that you will understand it in this sections.

lets assume that we have the following binary number in the register DL,


mov DL, 10101111B ; equivalent to 175 in decimal
shl DL, 1 ; means shift the binary number in DL to the left by "one" bit



the outcome of the previous instructions will be as follows:
1- DL will be equal to “0101 1110″ (moved the MSB to the C-flag and added “zero” to the right)
0101 1110 is equivalent to 94 in decemal.
2- C-flag will be equal to “one”, because the bit we moved from the binary number was “one”.
if we keep on repeating the shift instruction (shl – SHift to the Left) on the same binary number we will get the following results:

Left Shifting:

Code———–Number before shifting ———Number after shifting
shl DL, 1 ———–10101111 (175 decimal)——–01011110 (94 decimal)
shl DL, 1 ———- 01011110 (94 decimal) ———10111100 (188 decimal)
shl DL, 1 ———–10111100 (188 decimal) ——-01111000 ( 120 decimal)
shl DL, 1 ———–01111000 ( 120 decimal) ——11110000 (240 decimal)

if you keep on going you will naturally get all zeros at the end.
Now you might ask “Why is this guy keep on putting the decimal equivalents???”
if you noticed the pattern you will find that if we shifted a “zero” from the left, the number will be DOUBLE the number (as in the case in the second and fourth instructions) before shifting, but if we shifted a “one” the new number will just be different.

Right Shifting:
Code————Number before shifting ———- -Number after shifting
shr DL, 1 ——-10101111 (175 decimal) ———- 01010111 (87 decimal)
shr DL, 1 ——- 01010111 (87 decimal) ———- 00101011 (43 decimal)
shr DL, 1 ——-00101011 (43 decimal) ———- 00010101 (21 decimal)
shr DL, 1 ——-00010101 ( 21 decimal) ———- 00001010 (10 decimal)

here the pattern is terribly clear!!! as we shift a bit from the right the number will always be halved (i.e. divided by two) no matter what bit you shift (“zero” or “one”) if the number is odd the result after division will be lower rounded (e.g. 175/2 = 87.5) the number will be 87. again obviously if we keep on using right shifting instruction, the number will be halved everytime we use the instruction and naturally we will get all zeros at the end.

Example of using shift instructions:

this example will illustrate the importance of the shift instructions. if any of you have taken a course intitled “Digital Logic” (which most of you probably took it, because its essential prerequisite to assembly programming) you will be familiar with the terms “even parity” and “odd parity”. parity refers to the number of “ones” in a binary number (e.g. 1101 has “odd parity” because the number of “ones” in the number is “odd”), those are used to verify if a “message” sent by a computer has been received correctly in the other side. what happens is, after a message is sent, it transfers through the internet in the form of bits (zeros and ones) so, to verify if the message has been correctly sent and received the number of “ones” and whether the parity is odd or even is send along with the message, and when the receiver gets the message the first thing is to check the parity of the received message and compare it with the parity that has been sent by the sender, if they doesnt match then the message is definitely has been altered or some of the bits have been lost while transferring the message.
so, this program will check if the parity is “odd” or “even” in a particular binary number.


mov Ax, 0
mov Cx, 8
mov DL, 10101111B
Next: shl DL, 1
JC AddOne ; jump if C-flag = 1
loop Next
JMP Done
AddOne: inc Ax ; increment number of ones
loop Next
Done: mov BL, 2
div BL ; divide number of ones by 2
mov AL, AH
mov AH, 0
call putDec ; “0″ if the number is even else “1″ if the number is odd

Read More