Follow

I am trying to calculate factorial of 30 using x86_64 assembly on Linux. Here's my code:

```
.global _start

.text
_start:
mov %RCX, 1 # counter
mov %RAX, 1 # factorial result
loop:
mul %RCX
inc %RCX
cmp %RCX, n
jle loop

.data
n: .byte 30

```

I am converting it using these two commands:

```
as file.s
ldd file.s -o a
```

However when running the executable `a`, segmention fault is raised. checking with gdb it seems that it is raised right at the first instruction after `_start`. Where am I wrong?

@farooqkz it's been forever since I worked with asm. I could be totally wrong. Shouldn't the first instruction be `mov $1, %rcx`? Since it looks like you're using AT&T syntax.

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.