简体   繁体   中英

How to type EOF in ARMv8 Assembly?

I am using the ARMv8 instruction set with Aarch64 execution state. The problem I am having, is were supposed to translate C code into assembly, and I am stuck on the following:

while (c != '\n' && c != EOF)
    c = getchar();

I know the basic setup for the while loop, as well as how to test c != '\\n' but the issue I have is how to write EOF in assembly. Can i just type

cmp c_r, EOF
b.eq skipwhile

or is it something else?

It depends on what code you're using in assembly for getchar() -

  • If you're just using a call to the assembly version of standard C library getchar() , then you can test with the C library's definition of EOF - normally -1 .
  • If you're implementing your own getchar() in assembly, then you need to match your test to the return value of your getchar() implementation when it gets to the end-of-file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM