ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
telnet_ping, you should provide more context to your question. You've posted to a programming forum, so evidently, this is a programming question. We need more information about things like the language you are using, any particular libraries that might be related, the nature of the program you are trying to write, etc.
A code snippet (in code tags, please) and any error messages that are emitted by compilers, linkers, runtime errors, and such would probably be useful, as well.
--- rod.
I take it you are taking an assembly class and have a quiz coming up or something? The zero flag is set whenever the result of some operations are zero. For instance:
Code:
mov ax,10
sub ax,10
Would set the zero flag. Mostly these are arithmetic instructions, such as add, sub, mul, etc. It is also affected by some other instructions; most notable, cmp (which essentially does a subtraction anyways, just doesn't store the result).
H.O. bits are "High order bits". The name is somewhat self explanatory, but, for example, take the byte 00111100 as an example. The high order bits are 0011 (the highest half). The other half is the low order bits (1100). When actually programming in assembly, the high order bits don't necessarily come first. The x86, for example, is what is called "little endian". This means that it stores its low order bytes first in memory (notice bytes, not bits). This means, a 32 bit integers like: 01011111 00000011 11000000 00000000 is actually stored as 00000000 11000000 00000011 01011111 (bytes are reversed).
If you don't have a text book for your course, you should buy one now. Any book should have this information covered in detail (ie. read it). You can even download a free book; The Art of Assembly (google for it).
i just need to code in assembly that is y. so i thought of learning the basis. i have some more to ask....
will the carry flag set for this operation and y?
Code:
mov ax,5
and ax,4
and u said about little Endian.. is there any advantage for little over big?? or vice versa???
i dint get the explanation for SAR & SHR ...
it says .... SAR is used for signed division and its said that SAR truncate to -infinity were as SHR to positive.
and why is -15>>2 is -4
and 15>>2 3 can u specify the explanation in bit patterens
and finaly.....
now i learned to write assembly coding.. so could u plz tell me how to compile .asm file and start executing......
i am using debian kernel 2.6
thank you very much!!
Last edited by telnet_ping; 09-13-2007 at 12:45 AM.
telnet_ping, you should provide more context to your question. You've posted to a programming forum, so evidently, this is a programming question. We need more information about things like the language you are using, any particular libraries that might be related, the nature of the program you are trying to write, etc.
A code snippet (in code tags, please) and any error messages that are emitted by compilers, linkers, runtime errors, and such would probably be useful, as well.
--- rod.
consider the snipper
Code:
mov ax,5
and ax,4
i dint complied i asked this out of curiosity... since there these thing are programming basics i had posted in this forum...
Glad to see you're learning assembly, definitely helps w/ programming in general.
The most basic question should really be answered first.
Quote:
Originally Posted by telnet_ping
and finaly.....
now i learned to write assembly coding.. so could u plz tell me how to compile .asm file and start executing......
i am using debian kernel 2.6
thank you very much!!
Firstly, I use NASM. It is a GREAT assembler and works on many OS (on x86 & AMD64/EMT64. Start w/ a basic NASM program (I'm assuming you are using linux)...
nothing.asm (works on both 32 and 64 bit)
Code:
global _start
section .text
_start:
mov ebx, 0 ; return code
mov eax, 1 ; exit
int 0x80 ; linux interrupt
Now assemble it to an ELF object file (32 bit)
Code:
nasm -f elf nothing.asm
or 64 bit.
Code:
nasm -f elf64 nothing.asm
This should create a file nothing.o. Now link it and execute it.
Code:
ld -s -o nothing nothing.o
./nothing
You can also link it to the C library. Here is a quicky I wrote to test if various instructions set the zero flag.
test_zero.asm (64 bit)
Code:
cpu X64
extern puts
global main:function
section .data
yes db "Zero flag is set", 0
no db "Zero flag is not set", 0
section .text
main:
xor eax, eax ; eax = 0, bitwise binary operators set zero flag
call check_zero ; YES
xor eax, eax
inc eax ; zero flag cleared
mov eax, 10 ; mov instruction doesn't touch zero flag
call check_zero ; NO
inc eax ; inc is arithmetic, eax + 1 = 11
call check_zero ; NO
sub eax, 11 ; arithmetic, eax - 11 = 0
call check_zero ; YES
add eax, 12 ; add is arithmetic, eax = 12, zero flag is cleared
and eax, 0 ; bitwise binary operators set zero flag (if 0)
call check_zero ; YES
mov eax, 9 ; eax = 9
xor ebx, ebx ; ebx = 0
mul ebx ; eax = eax * ebx = 0
call check_zero ; YES
mov ebx, 8 ; ebx = 8
mov eax, 8 ; eax = 8
cmp eax, ebx ; eax == ebx (eax - ebx = 0)
call check_zero ; YES
ret
check_zero:
push rdi
push rbp
mov rbp,rsp
mov rdi, no
jnz .print_no
mov rdi, yes
.print_no
push rax
call puts
pop rax
mov rsp,rbp
pop rbp
pop rdi
ret
You should really read up on the calling convention differences between 64 and 32 bit (in a nutshell, on 32 everything is pushed onto the stack, on amd64 the args are stored in rdi, rsi, rdx, rcx, r8, and r9 (xmm0-7 for floating point args) first, then pushed onto the stack).
Quote:
Originally Posted by telnet_ping
will the carry flag set for this operation and y?
Try modifying the program I gave you above and find out (jnc instead of jnz).
Quote:
Originally Posted by telnet_ping
and u said about little Endian.. is there any advantage for little over big?? or vice versa???
They are both found in the wild (x86 is little endian, Sparc, PPC, and ARM are big endian). Technically, I wouldn't say one is better than the other. In terms of programming, little endian does let you cast a bit easier (since the same memory address could be used when an int is cast to a char for instance -- think why), but I would not say that makes it better in any way. Big endianess is a bit more logical, since it is what would be expected.
Quote:
i dint get the explanation for SAR & SHR ...
it says .... SAR is used for signed division and its said that SAR truncate to -infinity were as SHR to positive.
and why is -15>>2 is -4
and 15>>2 3 can u specify the explanation in bit patterens
GET THE NASM DOCUMENTATION. It has a list of all x86 instructions along w/ a description (in the appendix). SHR always uses 0 to fill in the spots left by shifting the buts to the right. SAR takes the left most bit, and uses that to fill in the spots left by shifting to the right. Think about how negative numbers are stored, then think about what -15 would look like shifted to the right twice using SHR and then SAR.
BTW!!!! If you have a amd64 or emt64 (Intel), you will need to use NASM 0.99.02. 0.98.* only supports x86 (32 bit), and this is the stable version. Most linux distros will have packages for 0.98.* rather than 0.99.02, so you may need to compile 0.99.02 from the source.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.