Reputation: 2225
I am trying to write a simple x86 assembly program which compares the unsigned values in AL
, BL
and CL
respectively, and moves the smallest to BH
. The code is actually given to me as an example and I am trying to make it run. I have typed in the example code as it was given to me as follows:
bits16
org 0x100
main:
mov al,7 ; In a big program one would read in the
mov bl,8 ; values for AL, BL and CL. Here we initialse
mov cl,5 ; the values for testing purposes
mov bh,al ; Mov AL to BH
cmp bh,bl ; Compare BH to BL
jbe label_1 ; If BH <= BL, jump to label_1
; else
mov bh,bl ; move BL to BH
label_1:
cmp bh,cl ; Compare BH to CL
jbe label_2 ; If BH <= CL, jump to label_2,
; else
mov bh,cl ; mov CL to BH
label_2:
; BH contains the smallest value
message: db 'Hello World',0ah,0dh,'$'
int 20h ; Terminate program
When compiling this, I get a warning saying:
"label alone on a line without a colon might be an error
".
How do I fix this and get the code to compile and behave as described in the opening sentence? I understand that the compiler is hinting the answer to me, but I am new to x86 programming and would therefore appreciate some guidance. Additional explanations on what is a label, in this specific context, would also help.
Upvotes: 0
Views: 1114
Reputation: 9331
You have written the first instruction incorrectly and nasm is interpreting that as a label
bits16 ; no space between 'bits' and '16'
Change it to:
bits 16 ; space between 'bits' and '16'
A label is basically an identifier in the text segment of your code which represents a location. You can jump to it directly from anywhere in the program if it is a global label. How do you create a label?
label:
Just a sequence of characters with a colon at the end. Note that sometimes you will encounter labels that begin with a period .
. Those are local labels.
In simple words, Labels are used to create procedures and loops in assembly language mostly. You can do things without labels but then life would become very difficult.
Upvotes: 4