d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Assembly - When To Use Dc, Equ, Ds > Motorola 68k
Add Reply New Topic New Poll
Member
Posts: 24,396
Joined: Oct 21 2007
Gold: 0.38
Mar 20 2013 10:28am
Topic.

Still very new to assembly, just getting into defining and using constants / variables, but I'm not 100% sure on when to use EQU and when to use DC/DS, and can't find anything on google explaining it.

Thanks. :LOVE:
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Mar 20 2013 11:53am
i am not 100% sure because i have not used them in my assembly before (32/64bit at&t linux) but from what ive read they are segement registers to help point your program to your next byte of code.

equ on the other hand is short for equate. it takes your equation and stores the output at a label or register you specify (if i recall correctly). i usually use it to calculate the length of strings so i may pass it to system calls that print data to STDOUT.

something like this

Code
section .data                       ; section for initialized data
str:     db 'Hello world!', 0Ah     ; message string with new-line char at the end (10 decimal)
str_len: equ $ - str                ; calcs length of string (bytes) by subtracting this' address ($ symbol)
                                    ; from the str's start address


an example of how i would use it is

Code
.section .data
enter_pass:
.ascii "Enter the password\n\0"
password:
.ascii "abgirl"
.equ password_len, . - password

.section .bss
.equ in_pass_size, 500
.lcomm in_pass, in_pass_size

.section .text
.global _start

_start:

movl $1, %ebx
movl $enter_pass, %ecx
movl $20, %edx
movl $4, %eax
int $0x80;print string to $1 (stdout)

movl $0, %ebx
movl $in_pass, %ecx
movl $in_pass_size, %edx
movl $3, %eax
int $0x80;grab input from STDIN ($0)


hopefully that helped you some

This post was edited by AbDuCt on Mar 20 2013 11:58am
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll