Ruuning assembly code in LLVM

I have assembly code as:
.file “ex.c”
.globl main # – Begin function main
.p2align 4, 0x90
.type main,@function
main: # @main


pushq	%rbp
.cfi_def_cfa_offset 16
.cfi_offset %rbp, -16
movq	%rsp, %rbp
.cfi_def_cfa_register %rbp
subq	$16, %rsp
movl	$0, -4(%rbp)
movabsq	$.L.str, %rdi
movb	$0, %al
callq	printf
xorl	%ecx, %ecx
movl	%eax, -8(%rbp)          # 4-byte Spill
movl	%ecx, %eax
addq	$16, %rsp
popq	%rbp
.cfi_def_cfa %rsp, 8

.size main, .Lfunc_end0-main
# – End function
.type .L.str,@object # @.str
.section .rodata.str1.1,“aMS”,@progbits,1
.asciz “Hello”
.size .L.str, 6

.ident	"clang version 10.0.0-4ubuntu1 "
.section	".note.GNU-stack","",@progbits
.addrsig_sym printf

When I use llvm-as -o test.o test.s I am getting error as :
llvm-as: test.s:1:2: error: expected top-level entity

How can I create object code from assembly code in LLVM?

Thank You

Hello Aruna,

llvm-as takes LLVM-assembly that is .ll file and output LLVM byte code that is .bc file.

clang -c test.s will give an object (in .o format) file.

For backend, most useful tool is llc(LLVM static compiler).
llc -filetype=obj test.ll will give also you object code(.o file) from llvm assembly(.ll) file.

Also in any open source project, your best friend is always documentation.
See the llvm tools command guide to know their uses.