أحمد الحربي/دكتور
1
2
Assembly Language
When the user wishes to communicate with the computer, he find himself may use
a spectrum of languages:
English Best for programmer
C/C++
Java
today.
¾ Reading is easier.
for other machines. These examples may be easily translated into the
machine he is using.
4
An Assembly Language Program
will be loaded in core. So, we assume that program's starting address was
Thus there must be a way for us to load the base register with the
address of the program in core just prior to execution time. The BALR
and what that register will contain. The USING instruction tells both of
these things to the assembler and thus makes it possible for it to produce
correct code.
5
number before the F would cause multiple allocations, e.g. DS 100F
Program Comments
TEST START Identifies name of program
BEGIN BA LR 15,0 Set register 15 to the address of the next
instruction
USING BEGIN+2,15 Pseudo-op indicating to assembler register
15 is base register and its content is
address of next instruction
SR 4,4 Clear register 4 (set index=0)
L 3,TEN Load the number 10 into register 3
LOOP L 2,DATA(4) Load data (index) into register 2
A 2,FORTY9 Add 49
ST 2,DA TA(4) Store updated value of data (index)
A 4,FOUR Add 4 to register 4 (set index = index+4)
BCT J,LOOP Decrement register 3 by 1, if result non-
zero, branch back to loop
BR 14 Branch back to caller
TEN DC F'10' Constant 10
FOUR DC F’4’ Constant 4
FORTY9 DC F'49' Constant 49
DATA DC F'1,3,3,3,3,
4,5,8,9,0' Words to be processed.
END
register to use as a base and what its contents will be. This is necessary
because no special registers are set aside for addressing, thus the
programmer must inform the assembler which register(s) to use and how
to use them.
produce the machine code with the correct base register and offset.
between the BALR, which loads the base register, and the USING,
The distinction will be clearer after we study the assembler, but for
now, note that a USING 'only provides information to the assembler but
does not load the register. Therefore, if the register does not contain the
7
address that the USING says it should contain, a program error may
result.
the program is and allows the user to give a name to the program. In this
4. END is a pseudo-op that tells the assembler that the last card of the
Here we will repeat the same example using literals, which are
are literals which containing 10, 49, 4 and replacement of the literal
8
The assembler translates the instruction L 3, = F'10' so that its
address portion points to a full word that contains a 10. Normally, the
However, the pseudo-op LTORG can tell the assembler to place the
it would have been impossible for the offset of the load instruction to
reach the literals at the end of our program. In this case, we would want
9
Observe that some pseudo-ops (e.g., START and USING) do not
generate machine code. Note also that the BR 14 instruction has been
10
Macro Language and Macro Processor
تتكرر في البرنامج ،ھنا تحدد مجموعة التعليمات بماكرو كما بالمثال التالي.
11
Example:
-ھو يضع كل تعليمة ماكرو مع مجموعة جمل اللغة المصدرية المقابلة لھا وھذا ما
يسمى توسيع الماكرو ).(Macro Expansion
-يجب أن يصمم معالج الماكرو بحيث ال يتأثر بشكل جمل لغة البرمجة المستخدمة
وال يعتمد مباشرة على تركيبة الكمبيوتر الذي ينفذ البرنامج.
-بعد إنتھاء معالج الماكرو من المعالجة ينتج ملف كما تم توضيحه بأعلى وھو يكون
INPUTللـ .Assembler
12
Source Object
Program Program
البرنامج Assembler البرنامج
المصدري الھدفي
-مثال :لبرنامج يستخدم تعليمات ماكرو وبه عدد " "٢ماكرو لتوضيح عملية توسعة
13