944,084 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 1543
  • Assembly RSS
Oct 5th, 2009
0

Creating a floppy image

Expand Post »
Ok so i have this floppy image that just prints a message now the problem that i am running into is that i have to jump to memory location 0x1000 and then jump back to the original place but have no clue how to do it this is what mbr looks like on the floppy: (i am using nasm)

org 0x7c00
xor ax,ax
mov es,ax
mov ah,0
mov al,3
int 10h

mov ah,13h
mov al,1
mov bh,0
mov bl,0ah
mov cx,mlen
mov dh,0
mov dl,0
mov bp, msg
int 10h

;jump to 0x1000 here
;print '$' here

mov dh,1
msg db "This is a message"
mlen equ $-msg
times 512-($-$$)-2 db 0
dw 0AA55h
Last edited by makaveli0129; Oct 5th, 2009 at 6:49 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
makaveli0129 is offline Offline
1 posts
since Oct 2009
Oct 5th, 2009
0
Re: Creating a floppy image
I'm no expert programming with 16 bit Intel or boot floppies(only did it once out of curiosity) but here's a website that addresses your question

http://www.emu8086.com/assembly_lang...torial_09.html
Reputation Points: 499
Solved Threads: 367
Postaholic
gerard4143 is offline Offline
2,197 posts
since Jan 2008
Oct 5th, 2009
0
Re: Creating a floppy image
I updated my boot disk that I made some time ago...It now supports a function call and a stack. The functionality I added is from any information I could find on Google so I can noway guarantee that this is the correct way to do this, all I know is that its works on my old PII computer....

assem code
Assembly Syntax (Toggle Plain Text)
  1. .code16
  2.  
  3. .section .data
  4.  
  5. .section .text
  6. .global _start
  7. _start:
  8. movw $0xb800, %ax
  9. movw %ax, %es
  10. movw $0x8000, %ax
  11. movw %ax, %ss
  12. movw $0xfffe, %sp
  13.  
  14.  
  15.  
  16. call tohere
  17.  
  18. loop1:
  19. jmp loop1
  20.  
  21.  
  22. tohere:
  23. movb $0x47, %es:0
  24. movb $0x1f, %es:1
  25.  
  26. movb $0x34, %es:2
  27. movb $0x1f, %es:3
  28.  
  29. movb $0x31, %es:4
  30. movb $0x1f, %es:5
  31.  
  32. movb $0x34, %es:6
  33. movb $0x1f, %es:7
  34.  
  35. movb $0x33, %es:8
  36. movb $0x1f, %es:9
  37.  
  38. movb $0x20, %es:10
  39. movb $0x1f, %es:11
  40.  
  41. movb $0x48, %es:12
  42. movb $0x1f, %es:13
  43.  
  44. movb $0x61, %es:14
  45. movb $0x1f, %es:15
  46.  
  47. movb $0x63, %es:16
  48. movb $0x1f, %es:17
  49.  
  50. movb $0x6b, %es:18
  51. movb $0x1f, %es:19
  52.  
  53. movb $0x65, %es:20
  54. movb $0x1f, %es:21
  55.  
  56. movb $0x72, %es:22
  57. movb $0x1f, %es:23
  58.  
  59. movb $0x20, %es:24
  60. movb $0x1f, %es:25
  61.  
  62. movb $0x46, %es:26
  63. movb $0x1f, %es:27
  64.  
  65. movb $0x6f, %es:28
  66. movb $0x1f, %es:29
  67.  
  68. movb $0x72, %es:30
  69. movb $0x1f, %es:31
  70.  
  71. movb $0x75, %es:32
  72. movb $0x1f, %es:33
  73.  
  74. movb $0x6d, %es:34
  75. movb $0x1f, %es:35
  76.  
  77. movb $0x73, %es:36
  78. movb $0x1f, %es:37
  79.  
  80. movb $0x20, %es:38
  81. movb $0x1f, %es:39
  82.  
  83. ret

These are the lines that I set up my stack. I move 0x8000 hex into the ss segment register and initialize the stack pointer to 0xfffe. Like I said I'm not sure if this is correct all I know is it works on my old PII
Assembly Syntax (Toggle Plain Text)
  1. movw $0x8000, %ax
  2. movw %ax, %ss
  3. movw $0xfffe, %sp

The code's in At&t syntax, sorry all I know. From this exe I stripped out the pertinent sections(everything but the header and footer) and did a little AWK magic and ended up with the hex array below

C code
Assembly Syntax (Toggle Plain Text)
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<fcntl.h>
  4.  
  5. char boot_buf[512] = {
  6. 0xB8,0x00,0xB8,0x8E,0xC0,0xB8,0x00,0x80,0x8E,0xD0,0xBC,0xFE,0xFF,0xE8,0x02,0x00,0xEB,0xFE,0x26,
  7. 0xC6,0x06,0x00,0x00,0x47,0x26,0xC6,0x06,0x01,0x00,0x1F,0x26,0xC6,0x06,0x02,0x00,0x34,0x26,0xC6,
  8. 0x06,0x03,0x00,0x1F,0x26,0xC6,0x06,0x04,0x00,0x31,0x26,0xC6,0x06,0x05,0x00,0x1F,0x26,0xC6,0x06,
  9. 0x06,0x00,0x34,0x26,0xC6,0x06,0x07,0x00,0x1F,0x26,0xC6,0x06,0x08,0x00,0x33,0x26,0xC6,0x06,0x09,
  10. 0x00,0x1F,0x26,0xC6,0x06,0x0A,0x00,0x20,0x26,0xC6,0x06,0x0B,0x00,0x1F,0x26,0xC6,0x06,0x0C,0x00,
  11. 0x48,0x26,0xC6,0x06,0x0D,0x00,0x1F,0x26,0xC6,0x06,0x0E,0x00,0x61,0x26,0xC6,0x06,0x0F,0x00,0x1F,
  12. 0x26,0xC6,0x06,0x10,0x00,0x63,0x26,0xC6,0x06,0x11,0x00,0x1F,0x26,0xC6,0x06,0x12,0x00,0x6B,0x26,
  13. 0xC6,0x06,0x13,0x00,0x1F,0x26,0xC6,0x06,0x14,0x00,0x65,0x26,0xC6,0x06,0x15,0x00,0x1F,0x26,0xC6,
  14. 0x06,0x16,0x00,0x72,0x26,0xC6,0x06,0x17,0x00,0x1F,0x26,0xC6,0x06,0x18,0x00,0x20,0x26,0xC6,0x06,
  15. 0x19,0x00,0x1F,0x26,0xC6,0x06,0x1A,0x00,0x46,0x26,0xC6,0x06,0x1B,0x00,0x1F,0x26,0xC6,0x06,0x1C,
  16. 0x00,0x6F,0x26,0xC6,0x06,0x1D,0x00,0x1F,0x26,0xC6,0x06,0x1E,0x00,0x72,0x26,0xC6,0x06,0x1F,0x00,
  17. 0x1F,0x26,0xC6,0x06,0x20,0x00,0x75,0x26,0xC6,0x06,0x21,0x00,0x1F,0x26,0xC6,0x06,0x22,0x00,0x6D,
  18. 0x26,0xC6,0x06,0x23,0x00,0x1F,0x26,0xC6,0x06,0x24,0x00,0x73,0x26,0xC6,0x06,0x25,0x00,0x1F,0x26,
  19. 0xC6,0x06,0x26,0x00,0x20,0x26,0xC6,0x06,0x27,0x00,0x1F,0xC3
  20. };
  21.  
  22. int main(int argc, char**argv)
  23. {
  24. int floppy_desc;
  25.  
  26. boot_buf[510]=0x55;//to make the floppy/image bootable
  27. boot_buf[511]=0xaa;//to make the floppy/image bootable
  28.  
  29. floppy_desc=open("/dev/fd0",O_RDWR);
  30. lseek(floppy_desc,0,SEEK_CUR);
  31. write(floppy_desc,boot_buf,512);
  32. close(floppy_desc);
  33. }

This will create a boot disk for a Intel machine that will create a stack and then call a function that will display some text and then loop forever...Note this program will only compile on a Linux box because of this line:

Assembly Syntax (Toggle Plain Text)
  1. floppy_desc=open("/dev/fd0",O_RDWR);

If you plan to use this on a windows box you'll have to port it...

With this example you should be able to call anywhere within your code section letting the call/ret opcodes and the stack sweat the details...
Last edited by gerard4143; Oct 5th, 2009 at 9:35 pm.
Reputation Points: 499
Solved Threads: 367
Postaholic
gerard4143 is offline Offline
2,197 posts
since Jan 2008
Oct 5th, 2009
0
Re: Creating a floppy image
Your origin in 7C00h indicated that you were booted
by the BIOS, but you want to jump to 0x1000?
When you've loaded nothing there???
Is 0x1000 a physical or segment address?

If it is a segment adress to transfer control to code a 1000:0000
and be able to return you would use a
far CALL and the called routine would use RETF to return.

CALL word 0x1000:0x0
Reputation Points: 36
Solved Threads: 19
Junior Poster
NotNull is offline Offline
198 posts
since Oct 2008
Oct 5th, 2009
0
Re: Creating a floppy image
To set up stack 64KB in length for segment number
0x8000, you would load SP with 0000, it may sound strange
but when something is pushed on the stack 0000 will become
FFFE because PUSH decrements SP by -2, hence every byte
of the stack will be used.

Assembly Syntax (Toggle Plain Text)
  1. mov ax, 0x8000
  2. mov ss, ax
  3. mov sp, 0x0
Reputation Points: 36
Solved Threads: 19
Junior Poster
NotNull is offline Offline
198 posts
since Oct 2008
Oct 5th, 2009
0
Re: Creating a floppy image
Click to Expand / Collapse  Quote originally posted by NotNull ...
To set up stack 64KB in length for segment number
0x8000, you would load SP with 0000, it may sound strange
but when something is pushed on the stack 0000 will become
FFFE because PUSH decrements SP by -2, hence every byte
of the stack will be used.

Assembly Syntax (Toggle Plain Text)
  1. mov ax, 0x8000
  2. mov ss, ax
  3. mov sp, 0x0
Yeah that is weird. I only guessed at that part because I couldn't find any doc's on initializing the stack pointer, but I knew the stack started high and worked its way down...Good bit of info. Thanks...
Reputation Points: 499
Solved Threads: 367
Postaholic
gerard4143 is offline Offline
2,197 posts
since Jan 2008
Jul 17th, 2010
0
Re: Creating a floppy image
please help me to learning programing viruses by assembly language
please help me to learning programing viruses by assembly language
please help me to learning programing viruses by assembly language
please please please please please please please please please please please please
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ko3dm is offline Offline
2 posts
since Jul 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: Assembly language newbie and virus source codes
Next Thread in Assembly Forum Timeline: String Help in 8086





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC