Site Logo

Example - 03move.asm - Data Moves

Website

Home | Previous | Next

Example - 03move.asm

; ---------------------------------------------------------------
; A program to demonstrate MOV commands. Mov is short for move.
; --------------------------------------------------------------- CLO ; Close unwanted windows. ; ===== IMMEDIATE MOVES ===== MOV AL,15 ; Copy 15 HEX into the AL register MOV BL,40 ; Copy 40 HEX into the BL register MOV CL,50 ; Copy 50 HEX into the CL register MOV DL,60 ; Copy 60 HEX into the DL register Foo: INC AL ; Increment AL for no particular reason. ; ===== INDIRECT MOVES ===== MOV [A0],AL ; Copy value in AL to RAM location [A0] MOV BL,[40] ; Copy value in RAM location [40] into BL ; ===== REGISTER INDIRECT MOVES ===== MOV [CL],AL ; Copy the value in AL to the RAM ; location that CL points to. MOV BL,[CL] ; Copy the RAM location that CL points ; to into the BL register. JMP Foo ; PRESS ESCAPE TO STOP THE PROGRAM END ; --------------------------------------------------------------- TASK ==== Look up the ASCII codes of the letters in H,E,L,L,O and move these ASCII codes to RAM addresses [C0], [C1], [C2], [C3] and [C4]. Run the program and watch how the text appears on the simulated VDU display. This is very much the same as what happens in the IBM PC running MS DOS. The program you write should work but if you continue to study low level programming, you will find much more efficient and flexible ways of solving this problem.

Step through the program and watch the register values changing. In particular, look at the RAM-Hex display and note the way that values in RAM change. Addresses [50] and [A0] are altered. You can copy the example program from the help page and paste it into the source code editor.

Addresing Modes

There are several ADDRESSING MODES available with move commands.

Immediate Addressing

A hexadecimal number is copied into a register. Examples...

MOV AL,15 ; Copy 15 HEX into the AL register
MOV BL,40 ; Copy 40 HEX into the BL register
MOV CL,50 ; Copy 50 HEX into the CL register
MOV DL,60 ; Copy 60 HEX into the DL register

Indirect Addressing

A value is moved to or from RAM. The ram address is given as a number like [22] in square brackets. Examples...

MOV [A0],AL ; Copy value in AL to RAM location [40]
MOV BL,[40] ; Copy value in RAM location [A0] into BL

Register Indirect Addressing

Copy a value from RAM to a register or copy a value from a register to RAM. The RAM address is contained in a second register enclosed in square brackets like this [CL]. Examples ...

MOV [CL],AL ; Copy the value in AL to the RAM location that CL points to.
MOV BL,[CL] ; Copy the RAM location that CL points to into the BL register.

Register Moves

Not available in this simulation.

A register move looks like this

MOV AL,BL

To do this using simulator commands, use

PUSH BL
POP AL

Push and Pop are explained later.

Calculated Addresses

Not available in this simulator.

Copy a value from RAM to a register or copy a value from a register to RAM. The RAM address is contained in square brackets and is calculated. This is done to simplify access to record structures. For example a surname might be stored 12 bytes from the start of the record. This technique is shown in the examples below.

MOV [CL + 5],AL ; Copy the value in AL to the RAM location that CL + 5 points to.
MOV BL,[CL + 12] ; Copy the RAM location that CL + 12 points to into the BL register.

Implied Addresses

Not available in this simulator.

In this case, memory locations are named. Address [50] might be called 'puppy'. This means that moves can be programmed like this.

MOV AL,puppy ; Copy the value in RAM at position puppy into the AL register.
MOV puppy,BL ; Copy BL into the RAM location that puppy refers to.

Home | Previous | Next

© C Neil Bauers 2003