All Questions

Tagged with
Filter by
Sorted by
Tagged with
12 votes
2 answers
4k views

GNU as .macro directive expansion

Is there a way to have GNU as only expand .macro directives in a .S file, producing another .S file without them? Similiar to what gcc -E does with C code. Note this is about the assembler .macro ...
Jürgen Strobel's user avatar
7 votes
1 answer
2k views

Weird Macros (TASM)

Consider the following macros: pixelFast MACRO ; This macro draws a pixel, assuming the coordinates are already loaded in cx&dx and the color is in al. xor bh, bh mov ah, 0ch int ...
Itamar's user avatar
  • 137
7 votes
0 answers
721 views

Eclipse CDT macro awareness in assembler files

Currently I am using Eclipse (3.5.x and 3.7.x) with the CDT plugin for several projects that contain besides .c and .h files also .S files with x86 (or IA64) assembler code. The problem is, that in ...
Jürgen Böhm's user avatar
6 votes
2 answers
10k views

Assembly language: macros vs procedures

I'm new to assembly language and this question came across to my mind: Which is better solution for structuring my code, macros or procedures? While code included in a macro is just copied to the ...
Catalin Vasile's user avatar
6 votes
1 answer
6k views

Issues using a local label in a macro in MASM

I'm to write a macro that takes E,NE,A,B... as a parameter and a single command i.e mov eax,ebx which would execute if the condition set by a preceding cmp operation is true. An example call would ...
Alex Johnson's user avatar
5 votes
1 answer
3k views

For-loop macro/preprocessor for assembly files in GCC

I am fairly certain I have seen this in code before, but I am unable to find any references on how to do it. I do expect this to be compiler or assembler specific. I want to define an function ...
sherrellbc's user avatar
  • 4,737
5 votes
2 answers
6k views

GCC ARM Assembly Preprocessor Macro

I am trying to use an assembly(ARM) macro for fixed-point multiplication: #define MULT(a,b) __asm__ __volatile__ ( \ "SMULL r2, r3, %0, %1\n\t" \ "ADD r2, r2, #0x8000\n\t" \ ...
Jonathan's user avatar
  • 489
5 votes
1 answer
5k views

Referencing operands/parameters in GNU assembler macros

I am currently trying to understand the concept of macros in the assembly language, specifically in GNU assembler, AT&T syntax for IA-32 (x86). The slides from my university say the following: # ...
typeduke's user avatar
  • 6,652
5 votes
3 answers
16k views

How to create a GNU GAS macro that expands to an expression like "(x+y*240)*2"?

I'm building a program for ARM Linux using GAS, but I want to do some macros to make my development some more smart. Then I want to know: How could I do a macro for this: (x+y*240)*2, were x and y ...
Nathan Campos's user avatar
4 votes
3 answers
10k views

struct or class in assembly

I need something like struct or class in c++ For example I need a class with an array and two attribute (size and len) and some function like append and remove . How can I implement this in assembly ...
Vahid Kharazi's user avatar
4 votes
3 answers
4k views

Call a C preprocessor macro multiple times (through a variable)

I'd like to clean up my assembly code and povide a way to call "NOP" multiple times through a macro: #define NOP() asm(" nop") #define NOP_N( N ) \ NOP(); \ NOP(); \ .... call NOP() N ...
Gui13's user avatar
  • 13.2k
4 votes
2 answers
10k views

Macros in x86 assembly coding

Can somebody please explain how to use macros in x86 assembly coding
user106300's user avatar
4 votes
1 answer
182 views

How do I write a macro to repeat something up to a specific address?

The .org directive advances the location counter to a specified offset, and fills the extra bytes with a specified value. .org 123, 1 @ Pads 1s until we reach address 123. I want to write a macro to ...
Maxpm's user avatar
  • 24.7k
4 votes
1 answer
1k views

How do you compare variable types in assembly?

This might be a bit of a stupid syntax question, but is there a way you can make conditional jumps based on variable type? I'm trying to write a macro (for a class) that can take a byte, word, or ...
Io-stream's user avatar
  • 109
4 votes
3 answers
361 views

Unable to understand following macro [duplicate]

I found below macro when i am going through kernel source code and I am unable to understand what it is doing. #define barrer() __asm__ __volatile__("":::"memory") Please some one clarify this.
Chinna's user avatar
  • 3,990
4 votes
1 answer
411 views

GNU Assembler GAS check if macro paramater is register

I want handle in case if macro argument (parameter) is a register. I expect I have similiar code like this but I'm sure it doesn't work due to lack my knowledge of directive syntax. .macro myMacro ...
Citra Dewi's user avatar
3 votes
3 answers
2k views

asm block in c++ as a macro

I would like to write a macro which converts everything to void* even the member functions. Here is the code: #define toVoidStar(xx,yy)\ __asm push ecx; \ __asm mov ecx, yy; \ __asm mov [...
DalekSupreme's user avatar
  • 1,493
3 votes
1 answer
369 views

Breaking long macro argument list in GNU assembler for AArch64

I'm writing assembly code targeting ARMv8 (AArch64) in GNU assembler. Not sure if it matters, but I'm coding directly in my ARMv8 target (a Raspberry Pi board) running Linux. I have a macro with a ...
swineone's user avatar
  • 2,568
3 votes
2 answers
1k views

x86 assembly: Using #define'd constants as arguments in calls to to #define's macros

I'm working on manually constructing an IDT table in x86 assembly. I have the following macros defined using the C preprocessor in my .S file: // sets up an entry in the idt for a trap type #define ...
justinbach's user avatar
  • 1,945
3 votes
1 answer
402 views

macro vs equ in nasm

I'm having trouble understanding the difference between the two, the following example really had me puzzled: section .data msg: db "Thank you" var: dd 0x31323334 len equ msg-4 section ....
giorgioh's user avatar
  • 377
3 votes
1 answer
62 views

How to replace the value of symbol in x86 assembly using gnu asembler macro? Compose register names like xmm0 from xmm(i)

.macro macro_name .set i, 0 .rept 8 movss (i * 4)(%rsi), %xmm(i) set i , i + 1 .endr .endm I wrote this macro to load 8 single precession floating point numbers into xmm registers to ...
arka's user avatar
  • 418
3 votes
1 answer
7k views

What is the effect of the assembler directive `.global`

When I run my code in MARS it doesn't need any .global directive and i know that MARS doesn't use that directive. Now when i ported my code to a particular assembler (MCB32) which runs from the ...
user avatar
3 votes
1 answer
569 views

Calling a table of function using repeat blocks or macros in GNU assembly

If I wanted to generate code that looks like this: CALL FUNC0 CALL FUNC1 CALL FUNC2 CALL FUNC3 CALL FUNC4 CALL FUNC5 ... CALL FUNC19 How can I use a repeat block generate such code, using something ...
squirem's user avatar
  • 227
3 votes
1 answer
1k views

Macro printing a value stored in a byte. Assembly masm

Assembly, masm Hey, I wrote macro which prints the 1 byte value stored in dane1 segment. I divide the value by 16, then i push reminder to stack until value==0. Then I pop reminders convert them to ...
Nowak Grzegorz's user avatar
3 votes
1 answer
1k views

MOV into a register specified by macro argument

I'm trying to execute a mov operation in a macro in AVR assembly. I want to specify the target by a numeric argument to a macro. I am using the Atmel Studio assembler. I'm trying to do something like ...
Thom Wiggers's user avatar
  • 6,996
3 votes
1 answer
725 views

error: junk `bswapl eax movl %eax' after register

I define a MACRO in GAS source code. But it is not compiled by gcc. The following is my defined MACRO. #define MSGSCHEDULE0(index) \ movl (index*4)(%rsi) ,%eax \ bswapl eax \ movl %...
Land's user avatar
  • 191
3 votes
1 answer
76 views

Tasm macros default value

In turbo assembler i have a macro subs macro x,y mov ax,x sub ax,y endm how can I give to y a default value, equal to 1, so I can write subs bx and ax becomes equal to bx - 1?
Vahag Chakhoyan's user avatar
3 votes
1 answer
986 views

how to expand TASM macros

Is there a way to expand macros with Borland's TASM ? I'd like to transform a TASM compatible .ASM file to see all his macros expanded. Couldn't find any options to do that.
franck's user avatar
  • 3,015
3 votes
1 answer
1k views

.weak assembler macro for MinGW GCC / C alternative

I have a modular C-Project with some different libraries/objects, which are only linked to the release if some conditions are met. This project is build with GCC 3.4.4 for PowerPC. So all over my ...
Toby's user avatar
  • 3,845
3 votes
0 answers
102 views

Passing a subset of a macro's arguments to another macro in NASM

I've been experimenting with macros in NASM recently, and despite reading the documentation, I still don't know if there is a way to pass a subset of a macro's arguments to another macro; and if there ...
dawmd's user avatar
  • 76
3 votes
0 answers
1k views

Macros vs subroutines in assembly

Statement: A subroutine cannot always be used to replace a macro in an assembly language program. Is the above statement true or false? My book has given false as an answer. But I cannot think of ...
rahul sharma's user avatar
3 votes
0 answers
2k views

How to use labels in Nasm macros

I am experimenting in Nasm assembly out of pure interest. I was wondering how I would go about using labels in a macro function. I have tried my code below and this gives me redefining label errors, I ...
user avatar
3 votes
0 answers
132 views

How to loop inside of a MACRO in x86 Assembly [duplicate]

I have a MACRO written like this: putspaces MACRO numspaces push ecx ;pushes ecx reg onto stack for use mov ecx, numspaces ;move the integer param numspaces into ecx for ...
Chisx's user avatar
  • 1,986
2 votes
1 answer
3k views

How do i define macros in NASM x86

I'm trying to implement couple of macros for x86 project. I just moved from MARS mips assembly so dont judge my incompetence. I think I'm doing everything as in this guide https://www.tutorialspoint....
Marcin Tarłowski's user avatar
2 votes
4 answers
2k views

macro vs procedure in assembly

I'm learning now how to use macros in assembly language. I know that macros are faster than procedures because there's no costly jumps, only copying the lines. But I don't understand why macros take ...
Mickey's user avatar
  • 490
2 votes
1 answer
320 views

Is there a point in using %assign over %define?

It seems to me that the %define directive to define a single-line macro is just the %assign directive with additional features like an ability to get parameters. If that's the case, what's the point ...
CrazyMan's user avatar
2 votes
1 answer
72 views

Is it possible to to use the outer macro parameter is used by inner macro?

data segment str db "hello$" str2 db "world$" data ends adds macro a,b lea si,a lea di,b endm subs macro x,y adds x,y endm code segment assume cs:...
ViswaDecoders's user avatar
2 votes
2 answers
101 views

What is this code trying to do?

I'm trying to understand how the following code is working: #define M32toX128(x128,m32) __asm__ \ ("movddup %1, %0\n\t" \ "movsldup %0, %0" ...
atoMerz's user avatar
  • 7,642
2 votes
1 answer
251 views

Trouble with MIPS macros in SPIM

I'm struggling to get a macro to work in my lab code. This is how I wrote it: .macro print_char($arg) li $v0, 11 add $a0, $zero, $arg syscall .end_macro I don't think it should matter ...
polar's user avatar
  • 204
2 votes
1 answer
3k views

Understanding NASM Macro

I've come around this macro in a assembly source file and I just can't figure out how it's working. So first I come around this function (hevc_deblock.h): cglobal hevc_v_loop_filter_chroma_8, 3, 5, ...
meneldal's user avatar
  • 1,727
2 votes
1 answer
2k views

Expression in GCC ARM assembly macro

I'm in need of macros with many registers involved, like : .macro load128bytes vld1.8 {d0, d1, d2, d3}, [r0]! vld1.8 {d4, d5, d6, d7}, [r0]! vld1.8 {d8, d9, d10, d11}, [r0]! vld1.8 {d12, d13, ...
Jake 'Alquimista' LEE's user avatar
2 votes
1 answer
698 views

MASM: .IF with signed numbers comparison

I have: mov ecx, r .if ecx < 0 mov cl, 0 .elseif ecx > 255 mov cl, 255 .endif mov [eax + 2], cl r is signed integer. I want it to cap it within byte limit. ...
Hooch's user avatar
  • 29.3k
2 votes
1 answer
721 views

How can I concatenate a label not in a macro definition? (in GAS assembler)

I want to do this: i=0 .rept 3 add rcx,[a?(i*2+1)] i=i+1 .endr It should output this: add rcx,[a1] add rcx,[a3] add rcx,[a5] I can't find any solution to this problem. I don't want it to ...
BinaryBurst's user avatar
2 votes
1 answer
632 views

Concatenate in macro assembler

I want use in my code something like that: .data? my_macro_var db MAX_PATH DUP (?) .code mov esi, offset my_macro_var my_macro esi, "hello and bye" For that i create this macro but i get few ...
user1959076's user avatar
2 votes
1 answer
610 views

Nasm: Macros not expanded as operands to instructions

I wrote a small bit of assembly for nasm like this: %macro register 1 %if %1 = 0 rax %elif %1 = 1 rbx %elif %1 = 2 rcx %endif %endmacro add register(1), ...
Matthew Sainsbury's user avatar
2 votes
1 answer
5k views

passing values in MIPS macros

I've been studying MIPS as an introduction to assembly, and recently started playing with macros. What I want to be able to do is pass a value generated by another macro, or just any value in any ...
user3715913's user avatar
2 votes
1 answer
168 views

How do I force a constant C-expression evaluation for use as a constant in a .S file?

A header file I'm including from /usr/include/**/asm (rudely?) uses simple C expressions to express an offset from a base value, i.e.: #define __NR_exit (__NR_SYSCALL_BASE+ 1) ...
cdleary's user avatar
  • 70.5k
2 votes
1 answer
768 views

How to reverse an array is assembly?

I'm trying to write a simple program that reverses an array. It almost works, well it works for the first half of the array anyway. The term in the middle is always "0" and then it returns to the ...
Io-stream's user avatar
  • 109
2 votes
1 answer
88 views

Assembly macro check argument

Well, a new strange problem occurred within assembly (especially tasm) CheckInfo MACRO arr:REQ, length:REQ, arr_type := <l> mov bx, arr mov cl, length mov si, 1 IF arr_type eq &...
Olexiy  Pyvovarov's user avatar
2 votes
1 answer
664 views

Average in assembly 8086 (macro error)

The code below computes the average of 20 user entered numbers. It works fine when I disable ShowMsg msg2 (make it a comment), but when its enabled, I get this error : INT 21h, AH=09h - address: ...
Asnira's user avatar
  • 313