WMLScript Primer: The Bytecode View
WMLScript Primer
The Bytecode View
To fit the narrow bandwidth in wireless communication, both WML and WMLScript code are compiled into a bytecode on the server and then sent to the user agent. The bytecode is a binary representation of the text-based WML and WMLScript code. It is structured very similarly to binary executable files. It consists of instruction sets, opcodes, addresses, etc. The advantage of bytecode files over binary executable files is that it is machine independent. You compile it once and run on any machine capable of running WMLScript interpreter. From now on, when you hear the term compiled once - run everywhere, you'll know where it is coming from. Let's examine the bytecode of the mortgage example from the previous page. As you recall, the size of mortgage.wml
is 1071 bytes. Its bytecode's length is 446 bytes (more than 2x reduction in size). Here is the bytecode:
00000000 01 04 6A 20 70 72 69 6E-63 69 70 61 6C 00 69 6E ..j principal.in
00000010 74 65 72 65 73 74 00 6E-75 6D 5F 70 61 79 6D 65 terest.num_payme
00000020 6E 74 73 00 7F E7 55 03-63 61 72 64 31 00 36 03 nts..?U.card1.6.
00000030 4D 6F 72 74 67 61 67 65-20 43 61 6C 63 00 23 01 Mortgage Calc.#.
00000040 60 03 20 50 72 69 6E 63-69 70 61 6C 3A 20 00 AF `. Principal: .¯
00000050 12 03 2A 4E 00 21 83 00-36 03 50 72 69 6E 63 69 ..*N.!..6.Princi
00000060 70 61 6C 3A 00 4D 03 31-35 30 30 30 30 00 01 26 pal:.M.150000..&
00000070 03 20 49 6E 74 65 72 65-73 74 3A 20 00 AF 12 03 . Interest: .¯..
00000080 2A 4E 00 21 83 0A 36 03-49 6E 74 65 72 65 73 74 *N.!..6.Interest
00000090 3A 00 4D 03 38 2E 30 30-00 01 26 03 20 4E 75 6D :.M.8.00..&. Num
000000A0 20 70 61 79 6D 65 6E 74-73 3A 00 AF 12 03 2A 4E payments:.¯..*N
000000B0 00 21 83 13 36 03 4E 75-6D 2E 20 70 61 79 6D 65 .!..6.Num. payme
000000C0 6E 74 73 3A 00 4D 03 33-36 30 00 01 26 03 20 50 nts:.M.360..&. P
000000D0 61 79 6D 65 6E 74 20 3D-20 00 7D 42 70 61 79 6D ayment = .}Bpaym
000000E0 65 6E 74 00 01 E8 38 18-03 43 61 6C 63 75 6C 61 ent..?8..Calcula
000000F0 74 65 00 01 AB 4A 03 6D-6F 72 74 67 61 67 65 2E te..«J.mortgage.
00000100 77 6D 6C 73 23 70 61 79-6D 65 6E 74 28 27 70 61 wmls#payment('pa
00000110 79 6D 65 6E 74 27 2C 27-00 80 00 03 27 2C 27 00 yment','....','.
00000120 80 0A 03 27 2C 27 00 80-13 03 27 29 00 01 01 E8 ...','....')...?
00000130 3A 18 03 48 65 6C 70 00-01 AB 4A 03 23 00 8D 01 :..Help..«J.#...
00000140 01 01 01 E7 55 8D 36 03-48 65 6C 70 00 01 60 7D ...?U.6.Help..`}
00000150 03 50 72 69 6E 63 69 70-61 6C 00 01 03 20 2D 20 .Principal... -
00000160 00 03 24 00 03 20 61 6D-6F 75 6E 74 00 26 7D 03 ..$.. amount.&}.
00000170 49 6E 74 65 72 65 73 74-00 01 03 20 2D 20 65 2E Interest... - e.
00000180 67 2E 20 37 2E 35 00 26-7D 03 50 61 79 6D 65 6E g. 7.5.&}.Paymen
00000190 74 73 00 01 03 20 2D 20-65 2E 67 2E 20 33 36 30 ts... - e.g. 360
000001A0 20 66 6F 72 20 33 30 20-79 65 61 72 73 00 26 E8 for 30 years.&?
000001B0 46 18 03 42 61 63 6B 00-01 32 01 01 01 01 F..Back..2....
This display can be generated only by an application that can interpret WMLScript. We used the Nokia WAP Toolkit for this. It supports two views: WML and bytecode. The above output is mortgage.wml
's bytecode representation. Each byte is represented by two hexadecimal characters and is surrounded by white space. The left column shows the byte number (from the beginning of the file) of next row's first byte (in hexadecimal notation). For example, the top entry on the most-left column is 10, which is 16 in decimal notation. Each line includes 16 bytes, with a separation hypen between the first and last eight. If we start counting from zero, byte number 16 is the first one on the second row. The most-right column tries to interpret each byte as an ASCII character. Some of the interpretations are garbage, of course, but some of them reconstruct the original WML code.
Next: How to identify differences between WMLScript and JavaScript
Produced by Yehuda Shiran and Tomer Shiran
Created: May 22, 2000
Revised: June 18, 2000
URL: https://www.webreference.com/js/column62/6.html