Minggu, 27 Februari 2011

tutorial belajar bahasa ASSEMBLY tingkat dasar (in english)

 ASSEMBLY atau bahasa pemograman tingkat rendah (low-level programming language)

mudah-mudahan menambah pengetahuan kita.



107A:0102 MOV DL,41
107A:0104 INT 21
107A:0106 INT 20
-g 102 <-- set up a break point at 107A:0102
At this point the program will stop, display all registers and the current instruction.


Hex:
This can be very useful. It subtracts and adds to hexadecimal values:
-h 2 1
0003 0001 <-- 2h + 1+ = 3h and 2h - 1h = 1h
This is very useful for calculating a programs length, as you will see later.


Input:
This is one of the more advanced commands, and I decided not to talk about it too much
for now. It will read a byte of data from any of your computers I/O ports (keyboard,
mouse, printer, etc).
-i 3FD
60
-
Your data may be different.
In case you want to know, 3FD is Com port 1, also known as First Asynchronous Adapter.


Load:
This command has 2 formats. It can be used to load the filename specified with the
name command (n), or it can load a specific sector.
-n c:\command.com
-l
This will load command.com into debug. When a valid program is loaded all registers will 
be set up and ready to execute the program.
The other method is a bit more complicated, but potential also more usefull. The syntax
is 
L <address> <drive letter> <sector> <amount to load>
-l 100 2 10 20
This will load starting at offset 0100 from drive C (0 = A, 1 = B, 2 = C, etc), sector
10h for 20h sectors. This can be useful for recovering files you deleted.


Move:
Move takes a byte from the starting address and moves it to the destination address.
This is very good to temporary move data into a free area, than manipulate it without
having to worry about affecting the original program. It is especially useful if
used in conjunction with the r command to which I will get later. Lets try an example:
-a <-- enter our original program so we have something
107A:0100 MOV AH,02 to work with
107A:0102 MOV DL,41
107A:0104 INT 21
107A:0106 INT 20
-m 107A:0100 L 8 107B:0100 <-- more 8 bytes starting from 107A:0100 into 107B:0100
-e 107B:0103 <-- edit 107B:0103
107B:0103 41.42 <-- and change it 42 (B) 
-d 107A:0100 L 8 <-- make sure it worked
107A:0100 B4 02 B2 41 CD 21 CD 20 ...A.!.
-d 107B:0100 L 8
107A:0100 B4 02 B2 42 CD 21 CD 20 ...B.!.
-m 107B:0100 L 8 107A:0100 <-- restore the original program since we like the 
changes.


Name:
This will set debug up with a filename to use for I/O commands. You have to include
the file extension, and you may use addition commands:
-n c:\command.com


Output:
Exactly what you think it is. Output sends stuff to an I/O port. If you have an
external modem with those cool lights on it, you can test this out. Find out what port
your modem is on and use the corresponding hex number below:
Com 1 = 3F8 - 3FF (3FD for mine)
Com 2 = 2F8 - 2FF
Com 3 = ??? - ??? (if someone knows, please let me know, I would assume though that it's
0F8 - 0FF.)
Now turn on the DTA (Data Terminal Ready) bit by sending 01h to it:
-o XXX 1 <-- XXX is the com port in hex
As soon as you hit enter, take a look at your modem, you should see a light light up.
You can have even more fun with the output command. Say someone put one of those BIOS
passwords on "your" computer. Usually you'd have to take out the battery to get rid of
it, but not anymore:
AMI/AWARD BIOS
-o 70 17
-o 71 17

QPHOENIX BIOS
-o 70 FF
-o 71 17

QGENERIC
-o 70 2E
-o 71 FF

These commands will clear the BIOS memory, thus disabling the password. Please note
however that these are fairly old numbers and BIOS makes constantly change them, so
they might not work with your particular BIOS.


Proceed:
Proceeds in the execution of a program, usually used together withy trace, which I 
will cover later. Like the go command, you can specify an address from which to start
using =address
-p 2
Debug will respond with the registers and the current command to be executed.


Quite:
This has got to be the most advanced feature of debug, it exits debug!
-q


Register:
This command can be used to display the current value of all registers, or to manually
set them. This is very useful for writing files as you will see later on. 
-r AX
AX: 011B
:5
-


Search:
Another very useful command. It is used to find the occurrence of a specific byte, or
series of bytes in a segment. The data to search for can by either characters, or a
hex value. Hex values are entered with a space or comma in between them, and characters
are enclosed with quotes (single or double). You can also search for hex and characters
with the same string:
-n c:\command.com <-- load command.com so we have some data to search in
-l
-s 0 l 0 "MS-DOS" <-- search entire memory block for "MS-DOS"
10A3:39E9 <-- found the string in 10A3:39E9
NOTE: the search is case sensitive!


Trace:
This is a truly great feature of debug. It will trace through a program one instruction
at a time, displaying the instruction and registers after each. Like the go command
you can specify where to start executing from, and for how long.
-a <-- yes, this thing again
107A:0100 MOV AH,02
107A:0102 MOV DL,41
107A:0104 INT 21
107A:0106 INT 20
-t =0100 8
If you leave out the amount of instructions that you want to trace, you can use the 
proceed (p) to continue the execution as long as you want.

1 komentar: