2017-12-11 11 views
1

다른 문자를 밀어 넣는 많은 push 명령어를 작성해야합니다. 나는 그것을 위해 매크로를 사용하고 싶다.Nasm 전 처리기 - 변수를 통해 주소 매개 변수

%macro push_multi 1-*  ; Accept between 1 and ∞ arguments 
    %assign i 1 
    %rep %0     ; %0 is number of arguments 
     push %{i} 
     %assign i i+1 
    %endrep 
%endmacro 

push_multi 'a', 'b', 'c' ; push 'a' then push 'b' then push 'c' 

그러나 nasm -E과 결과는 다음과 같습니다 : 나는의 n 번째 인수를 해결할 수있는 방법

push 'a' 
push 'b' 
push 'c' 

을 :

push %i 
push %i 
push %i 

내가이 원하는 이것은 내가 지금까지 한 일이다 변수가있는 매크로가 assign으로 생성 되었습니까?

답변

2

%rotate 1을 사용하면 매크로 인수 목록을 1 요소 씩 왼쪽으로 회전 할 수 있습니다. 이렇게하면 처음에 목록의 다음 요소가 효과적으로 배치됩니다. 목록의 첫 번째 요소는 항상 %1으로 참조 될 수 있습니다. 루프를 %rep %0 루프에 넣으면 매크로 인수 목록의 모든 요소를 ​​반복 할 수 있습니다. %rotate에 대한 NASM documentation이 말한다 :

%의 회전이 (표현 될 수있다) 단일 숫자 인수로 호출됩니다. 매크로 매개 변수는 여러 위치에서 왼쪽으로 회전합니다. % rotate 인수가 음수이면 매크로 매개 변수가 오른쪽으로 회전합니다. 당신은 당신이 -1과 반대 방향으로 회전 할 수 역의 목록을하려면

%macro push_multi 1-*  ; Accept 1 or more arguments 
    %rep %0     ; %0 is number of arguments pass to macro 
     push %1 
     %rotate 1   ; Rotate to the next argument in the list 
    %endrep 
%endmacro 

%rotate 첫째을 수행하여 : 귀하의 경우

이 작동합니다

%macro push_multi 1-*  ; Accept 1 or more arguments 
    %rep %0     ; %0 is number of arguments pass to macro 
     %rotate -1   ; Rotate to the prev argument in the list 
          ; If at beginning of list it wraps to end of list 
     push %1 
    %endrep 
%endmacro 
+0

완벽한! 감사! – Bilow