Author Topic: label address in variable  (Read 9325 times)

Offline akasei

  • Jr. Member
  • *
  • Posts: 8
label address in variable
« on: December 06, 2013, 01:10:35 PM »
i need to do something like that:

Code: [Select]
dw ( wyjatek_0 and 0xffff )
dw 0x0008
db 0x00
db 10001110b
dw ( ( wyjatek_0 and 0xffff0000 ) shr 16 )
dd ( wyjatek_0 shr 32 )
dd 0x00000000

wyjatek_0:
jmp wyjatek_0

Offline encryptor256

  • Full Member
  • **
  • Posts: 250
  • Country: lv
  • Win64 .
    • On Youtube: encryptor256
Re: label address in variable
« Reply #1 on: December 06, 2013, 05:03:31 PM »
Hi!

i need to do something like that:

Code: [Select]
dw ( wyjatek_0 and 0xffff )
dw 0x0008
db 0x00
db 10001110b
dw ( ( wyjatek_0 and 0xffff0000 ) shr 16 )
dd ( wyjatek_0 shr 32 )
dd 0x00000000

wyjatek_0:
jmp wyjatek_0

Cool, then start to do, something like that.
Encryptor256's Investigation \ Research Department.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: label address in variable
« Reply #2 on: December 06, 2013, 06:33:02 PM »
Sounds easy if you say it quick.

Nasm won't accept "and" or "shr" in this context (Masm/Tasm syntax?). Replace with "&" and ">>". Then Nasm whines about these operators can only be applied to a "scalar value". You won't find the word "scalar" in the friendly manual. The issue is that a label is a "relocatable value", and Nasm doesn't know what the final value will be - that's up to the linker. The difference between two labels is a "scalar value". Nasm will eat "( wyjatek_0 - $$)" ("$$" is "beginning of section"). That may or may not do what you want. You may need to add in the "origin"... which only the linker knows (unless you're assembling as "-f bin"). For 32-bit Linux, ld will put us at 0x8048000. I think 32-bit Windows is 0x400000(?). No idea for 64-bit code.

Looks like a descriptor of some kind? Doing some system programming, Akasei?

Best,
Frank


Offline akasei

  • Jr. Member
  • *
  • Posts: 8
Re: label address in variable
« Reply #3 on: December 07, 2013, 12:55:54 PM »
Looks like a descriptor of some kind? Doing some system programming, Akasei?
Yep! This is 64bit Interrupt Descriptor :) int 0x00

And beacuse this don't work i do it that way: (and losing more space :/)
Code: [Select]
create_int:
mov rdi, 0x3000 ; base address
mov rbx, 1000111000000000b ; P, DPL, S, Type and 0x00
mov rcx, 8h ; code descriptor selector

make_int_0:
mov rax, wyjatek_0
stosw ; low offset
mov word [rdi], cx ; code descriptor selector
add rdi, 2h
mov word [rdi], bx ; P, DPL, S, Type and 0x00
add rdi, 2h
shr rax, 10h ; middle offset
stosw
shr rax, 10h ; hight offset
stosd
xor rax, rax ; always zero
stosd

make_int_1:
mov rax, wyjatek_1
stosw
...
« Last Edit: December 07, 2013, 01:02:24 PM by akasei »