Author Topic: Run-time corrupted data in Insight debugger (really simple MOV instruction)  (Read 9530 times)

Offline muodostus

  • Jr. Member
  • *
  • Posts: 2
Hi,

I'm trying to learn assembly using Jeff Duntemann's excellent Assembly Language Step by Step, Third Edition: Programming with Linux.  However, I'm having issues with unexpected data showing up in the Insight debugger (a front-end to GDB which diplays register and address contents) for example:

The code
Code: [Select]
section .data           ; Section containing initialized data

section .text           ; Section containing code

global _start           ; Linker needs this to find the entry point (starting point labelled global)

_start:
    nop                  ; This no-op keeps gdb happy
    mov rax, 'WXYZ'
    mov rbx, 'AAAA'
    mov rcx, 'WXYZ'
    mov rdx, 0004h
    nop
; Put your experiments between the two nops

section .bss             ; Section containing uninitialized data (seems to be optional to include)


Is resulting in registers containing:

RAX: 0xcc5958cc instead of the expected  0x5a595857
RBX: 0xcccccc41 instead of the expected 0x41414141
RCX: 0xcccccccc instead of 0x5a595857
and RDX: 0xcc0000cc instead of 0x00000004

Similarly, when I try:
Code: [Select]
_start:
    nop                  ; This no-op keeps gdb happy
    mov ax, 067FEh
    mov bx, ax
    mov cl, bh
    mov ch, bl
    nop

... I'm getting problematic output whether I try to move the initial number into AX, EAX, or RAX.

I've using a 64-bit Ubuntu running 18.04.1 LTS.
One of the things that seem to be problematic is insight doesn't seem to be processing 64 bit (it may be expecting a 32 bit since it converts my registers to EAX when I try to use RAX).

So, I tried using a different makefile (from the author's website: http://duntemann.com/assembly.html)
I changed from using:

Code: [Select]
sandbox: sandbox.o
        ld -o sandbox sandbox.o
sandbox.o: sandbox.asm
        nasm -f elf64 -g -F stabs sandbox.asm -l sandbox.lst

to

Code: [Select]
sandbox: sandbox.o
        ld -o sandbox sandbox.o -melf_i386
sandbox.o: sandbox.asm
        nasm -f elf -g -F stabs sandbox.asm -l sandbox.lst

but, while that built, the debugger went into an infinite loop. :P

Before attempting that change at the command-line it seemed that the debugger is not stepping through the code correctly (misinterpreting opcode and mnemonics and resultingly producing garbage output).

I had some real basic ASM experience and an amatuerish level of C++ more than ten years ago; I'm not real well versed in Linux but would like to become eventually competent in all three of these.  Anyway, if I have to throw away insight or modify it somehow what will be a good course to try to proceed through this book and onto programs that actually work on my linux distro (and have a debugger that maybe is better than gdb for assembly).

I suppose the real question is how to set up an environment that allows me to proceed through this book (and other tutorials).  I'm contemplating getting a raspberry pi and learning ARM assembly instead... but in the meantime I'd like to work with this laptop and (complete and accessible -- if somewhat dated) textbook if possible.

Thanks in advance for any response.
« Last Edit: October 09, 2018, 01:42:41 AM by muodostus »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
I cannot help you with Insight or GDB. Jeff's page does not look encouraging for Insight. I happen to know that Jeff talked with Jeff Owens about debuggers. Jeff O. had "asmbug" and/or "minibug". Might help?

This is poor, but it does seem to display the expected number/ Any help at all?

Code: [Select]
; nasm -f elf64 myprog.asm
; ld -o myprog myprog.o
         
global _start
         
section .text
_start:
         
mov rax, "AAA"
call showraxh
mov al, 10 ; NL
call putc
         
exit:
mov rax, 60
mov rdi, 42
syscall

;--------

showraxh:

push rax
push rbx
push rcx
push rdx

mov rbx, rax
mov rdx, 16
.top:
rol rbx, 4
mov al, bl
and al, 0xF
add al, '0'
cmp al, '9'
jna .num
add al, 7
.num:
call putc
dec rdx
jnz .top

pop rdx
pop rcx
pop rbx
pop rax
ret

;----------

putc:
push rdx
push rsi
push rdi
push rax

mov rax, 1
mov rdi, 1
mov rsi, rsp
mov rdx, 1
syscall

pop rax
pop rdi
pop rsi
pop rdx
ret
;---------

Let us know if you have any success at all. 64 bit is not the best thing that happened to assembly language!

Good Luck,
Frank


Offline muodostus

  • Jr. Member
  • *
  • Posts: 2
Thank you.  I'll definitely have a closer look at that, give it a whirl, and report back.  :D

In the meantime, I found a couple other entry-level assembly tutorials and I'm looking to see if I can just use gdb to provide info on the registers and flags (to get run-time feedback that the code is doing what I expect).  The PDF I'm working through instead right now is  Programming from the Ground Up, version 1.0 -- which covers similar ground (geared to Linux users and explains things in-depth) but is using the AT&T syntax and the as assembler (which I view as an opportunity to get "multi-lingual" and flexible.   8) .  As I get more practice I'll experiment with programs converted over to nasm too though.

BTW, it's awesome to see that there's a community available for people to get feedback with low-level programming.  I think this, "systems" languages like C/Java, and scripted languages such as TCL, Ruby, and Python all have useful domains and each provide a lens so that folks aren't merely consumers of technology but active and productive engagers with it.