ZX Format #02
30 ноября 1995

Assembler - Assembler for Dummies

<b>Assembler</b> - Assembler for Dummies
Assembler for Dummies.


             (# 2)


(C) 1995 Michael Spitsyn

________________________________



            Flags



   Register "F" processor called the flag. What is it?


   Flag - is a variable that can have two states -
established (equal to unity) and
reset (zero). Therefore,
case "F" can be considered
as a set of eight flag bits.
We can only use
four of them: zero flag, flag
transport, the sign flag and the flag of the parity-overflow.



    Arithmetic operations.



   Arithmetic - the science is very,
very useful, we are constantly
something to consider: we add,
subtract, divide, multiply. About
how to do it in assembly language, we are now and we'll talk.


   We'll start with the easiest,
add one to something,
for example, to register the "A":

********************************

  LD A, NUBER

  INC A

  RET
********************************


   As you can see, it's very simple,
for this command is
"INC" - the growth rate (increase
unit), after it is an operand, ie, any register
or a register pair:

********************************

  INC A INC HL

  INC H INC DE

  INC E INC IY

  INC E INC (HL)

  INC (IX + N) INC (IY + N)
********************************


   If you need to increase by
unit of any memory cell, then do as follows:

********************************

  LD HL, ADDRES LD IX, ADDRES

  INC (HL) INC (IX +0)

  RET RET
********************************


   The first option is faster and more convenient if the work is
single-cell memory, but if
you are in the table, it
not economical and ugly. Compare: we need to increase to
unit first, fifth and tenth
bytes in the table below:

********************************

  LD HL, TABL +1 LD IX, TABL

  INC (HL) INC (IX +1)

  LD HL, TABL +5 INC (IX +5)

  INC (HL) INC (IX +10)

  LD HL, TABL +10 RET

  INC (HL)

  RET
********************************


   All that is said about the increase in per unit, we have
and for the decrement, ie, for
reduce by one:

********************************

  DEC A DEC HL

  DEC L DEC IX

  DEC H DEC DE

  DEC E DEC BC

  DEC D DEC IY

  DEC C DEC IX

  DEC B DEC (HL)

  DEC (IX + N) DEC (IX + N)
********************************


   Now suppose that we
necessary to increase the register "A" not
unit, rather than, say, ten:

********************************

  LD A, NUMBER

  ADD A, 10

  RET
********************************


   Folding can register "A"
with the number and other registers and
with the memory cell addressed to
register pairs of "HL", "IX" and
"IY". You can also add
register a pair of "HL", "IX" and
"IY".

( PureBasic 
- filesystem ) 

********************************


  ADD A, N ADD A, (HL)

  ADD A, A ADD A, (IX + N)

  ADD A, B ADD A, (IY + N)

  ADD A, C ADD HL, HL

  ADD A, D ADD HL, BC

  ADD A, E ADD HL, DE

  ADD A, H ADD HL, SP

  ADD IX, IX ADD IX, BC

  ADD IX, DE ADD IX, SP

********************************


   As you can see a set of commands is large enough. When 
performing This command may be

error:

********************************


  LD A, 45

  LD B, 230

  ADD A, B

  RET

********************************


   The sum of "A" and "B" has exceeded 255
and therefore in the "A" would be no 275,
and 20 (case "A" does not rubber);
so we know what happened
overflow, the processor sets a flag in the transport unit.
It remains only to check it out.


   Just like the "INC"
is "DEC", y "ADD" is also a
"Couple" is "SUB", and she
has its own peculiarities. The command "SUB" only works with 
the register "A", so when writing a mnemonic for this command 
"A" omitted:


********************************


  SUB N SUB C

  SUB A SUB H

  SUB B SUB D

  SUB E SUB (HL)

  SUB (IX + N) SUB (IY + N)

********************************


   Command affects the carry flag as well as "ADD."


   Besides a couple commands "ADD" and
"SUB", there is another pair.
Commands "ADC" and "SBC" work
taking into account the carry flag, ie,
with the addition or subtraction to
the result is added (subtracted) the value of carry flag.
To set the carry flag
There are two case teams - is "SCF"
and "CCF". "SCF" - set the flag
transport unit. "CCF" - set carry flag to zero.

********************************


  ADC A, N SBC A, N

  ADC A, A SBC A, A

  ADC A, H SBC A, H

  ADC A, L SBC A, L

  ADC A, D SBC A, D

  ADC A, E SBC A, E

  ADC A, B SBC A, B

  ADC A, C SBC A, C

  ADC A, (HL) SBC A, (HL)

  ADC A, (IX + N) SBC A, (IX + N)

  ADC A, (IY + N) SBC A,) IY + N)

  ADC HL, HL SBC HL, HL

  ADC HL, BC SBC HL, BC

  ADC HL, DE SBC HL, DE

  ADC HL, SP SBC HL, SP

********************************


   Now, examples of work teams "ADC" and "SBC":

********************************


  LD A, 10 LD A, 10

  LD B, 5 LD B, 5

  CCF CCF

  SBC A, B ADC A, B

  RET RET


  A = 5 B = 5 A = 15 B = 5

********************************


   Instead of two teams "CCF" and
"SBC A, B" can simply put "SUB B", the result will be
same.

********************************


  LD A, 10 LD A, 10

  LD B, 5 LD B, 5

  SCF SCF

  SBC A, B ADC A, B

  RET RET


  A = 4 B = 5 A = 16 B = 5

********************************


   As is evident from the results
significantly affect the carry flag
the result of the operation. When you subtract it subtracted 
from the result, while the addition of added to the result.



   On operations of addition and subtraction discussed almost 
everything, now we'll talk about the division and 
multiplication. Unfortunately SPECCY not has command of 
division and multiplication, but these teams can be composed of 
several others. For example, we need to multiply the contents 
of two registers - "A" and "C":


********************************


      LD A, 10

      LD C, 5

      LD B, A

      XOR A
LOOP ADD A, C

      DJNZ LOOP

      RET

********************************


   In the example, there are two new commands - "XOR A" and 
"DJNZ LOOP "." XOR A "clears the register

"A" and team "DJNZ LOOP" repeats all the commands with commands
label label (eg
"LOOP"), to the command "DJNZ" (after it should be the same 
label as in the beginning of the cycle), the number of 
repetitions is given in the register "B". Using the fact that 
multiplication M to N - is the addition of M

with itself N times, you can
razobratsya the example above.


   You can use this property to divide. Try it for yourself.


   The next time you talk about
teams compare and work with
bits.
________________________________






Other articles:

IS-DOS - Information: The news in the world IS-DOS

IS-DOS - How is it done No 2

IS-DOS - a beginner No 2

IS-DOS - No 2 users

IS-DOS - programmers No 2

Assembler - Assembler for Dummies

Iron - Revised: Pepeklyuchatel turbo / normal for the Scorpion ZS-256-Turbo

Iron - The provinces of: presenting a sound card General Sound.

Iron - Manufacturer: Create Soft - Returning to the printed

Iron - Manufacturer: KAY - turbirovanie Spectrum - Machines

Toys - Novella: 48 irons.

Toys - on the shelves: Carrier Command.

Interview - Interview with Sergei and Andrei Zonov Larchenko

Information - The authors of the journal

Information - From the authors

Information - Help

Information - Black Box

Contest

a rest - Something: Nervous Work

Mailbox - Classified Ad

Mailbox - Letters from readers

Premiere - Digital Studio v1.12

Programmers - Basic to all.

Miscellaneous - From the history of the Amiga.

Miscellaneous - Prospects for P / O.

Systems - music editor Instrument 3.01

What's New - Overview of new products: Night Hunter, Extreme, Grell & Falla, Duck Out, Internationl Ninja Rabbits, Italian Super Car, Sly Spy Secret Agent, The Turn, Sextris.


Темы: Игры, Программное обеспечение, Пресса, Аппаратное обеспечение, Сеть, Демосцена, Люди, Программирование

Similar articles:
Entry - poems and maintenance facilities.
Introduction - Out of this number We have repeatedly postponed due to the fact that we traded heavily Black Raven.
TREE NEWS - New version of software for Modems CDOS.
Navezli novya - Overview of new products software: Mirror, Last Hero of Light Force.

В этот день...   21 November