flat assembler
Message board for the users of flat assembler.

Index > Main > [RU] Help with converting MASM -> FASM

Author
Thread Post new topic Reply to topic
MIHIP



Joined: 14 Feb 2013
Posts: 130
MIHIP
Есть программа:
Code:
;=C6=> @07@01>B0BL ?@>3@0<<C ?@>25@:8 1>;LH>3> G8A;0 =0 45;8<>ABL G8A;>< 19. 
;>;LH>5 G8A;> 8<55B @07@O4=>ABL >B 1000 4> 2000 @07@O4>2 8 7040=> 2 A53<5=B5 
;40==KE :0: <0AA82 45AOB8G=KE @07@O4>2 >B <;04H8E : AB0@H8<.
.model small
.186
.stack 100h
.data
;5A7C5F6
mass  db 0f6h,0c5h,0a7h,05h        ;128  dup(33h);
msg db "bez osta4i$"
r dw 4
.code
start:  
   mov ax,@data
   mov ds,ax
        ;<5B>4 >B=8<0=8O
        ;?5@59B8 2 :>=5F 8 =0G0BL >B BC40
        mov bx,15 ;G8A;> =0 :>B>@>5 45;8<
        mov si, offset mass
        add si,3
        std
        xor ax,ax
        LODSB
        mov cx,r;@07<5@ <0A820 2 109BE
aaa1:
        cmp ax,bx
                jb m1;<5=LH5
                
                
                div bl
                
                
                 
        jmp n2  
m1:             
        mov ah,al       
n2:             
        LODSB
        
        loop aaa1
                
        
        cmp ah,0
        jne mexit
         
        
 mov ah,9
 lea dx,msg
 int 21h
 
mexit:
mov     ax,4c00h
int     21h


end start
        
    

;нужно разработать программу проверки большого числа на делимость числом 19.
;Большое число имеет разрядность от 1000 до 2000 разрядов и задано в сегменте
;данных как массив десятичных разрядов от младших к старшим.

Написана на tasm. Помогите перевести на fasm, и чтоб можно было писать числа с клавиатуры, и на консоль выводилось. Заранее спасибо.
Post 08 Apr 2014, 17:03
View user's profile Send private message Visit poster's website Reply with quote
sid123



Joined: 30 Jul 2013
Posts: 340
Location: Asia, Singapore
sid123
What's goin' on the forums, just because i only know english and use "Google Translate" LOL. doesn't mean people come around like this.......
Anyways,
hi MIHIP,
I recommend to use English wherever possible, since a lot of people may not be knowing your language, I used Google Translate and here's what I came up with:
Google Translate wrote:

, need to develop a test program for a large number divide the number 19.
, Has a large number of bit from 1000 to 2000 and set bits in the segment
; the data as an array of decimal places from younger to older.

Written in tasm. Help translate into fasm, and that it was possible to write a number from the keyboard and output to the console. Thanks in advance.

I guess what you want is translating the TASM code to FASM?
I can't really understand the first 3 lines of translation, (1/∞ reasons not to trust Google Translate when you go outside the country.)
And now for the code (I'll break it part by part)
Add this (for COM)
Code:
org 0x100
    

Code:
.model small 
    

Not needed, cut off.
Code:
.186 
    

Why bother using 80186, it was crap, so why not use 386+ Instructions when
we've got awesome stuff in 2014? Cut off.
Code:
.stack 100h 
    

I'm not sure about this but this should set the stack to 0x100 (which seems to be a "little" sane as a DOS program starts a 0x100, and the stack grows down, so yeah you can simply add this line of code somewhere in your code initialization:
Code:
......
;; Grab CS.
mov ax, cs
;; idk, but the CPU should clear interrupts while shifting stack
cli
;; Set Stack Segment to current code segment
mov ss, ax
;; set sp to 0x100
mov sp, 0x100
;; Restore IF to normal
sti
.....
    

I don't recommend setting the stack to 0x100, as it's just 256-bytes and you'll have a stack overflow quick, (128 word pushes or 64 dword should be enough to bring it to 0xFFFF)
Instead set the Stack Segment to 0x9000 and set stack pointer to 0, (to make it aligned), that's after a potential EBDA territory so you should be safe.
Code:
.data 
;5A7C5F6 
mass  db 0f6h,0c5h,0a7h,05h        ;128  dup(33h); 
msg db "bez osta4i$" 
r dw 4 
    

Not need, cut off .data, and shift the code to somewhere below in source
code (you shouldn't be executing the data section....)
Code:
.code 
    

Cut off.
Code:
start: 
        mov ax,@data 
        mov ds,ax 
    

Um, I have no idea what is equivalent to this in FASM, basically it seems to be giving the data segment to the data section, since we're COM, so DS=CS, no need. cut off or if you really want to be awesome:
Code:
;; awesomenessssss.
;; set DS=CS
mov ax, cs
mov ds, ax
    

Code:

        ;<5B>4 >B=8<0=8O 
        ;?5@59B8 2 :>=5F 8 =0G0BL >B BC40 
        mov bx,15 ;G8A;> =0 :>B>@>5 45;8< 
        mov si, offset mass 
    

No idea what those comments mean, but remove the "offset", since it's crap MASMery.
Code:
        add si,3 
        std 
        xor ax,ax 
        LODSB 
        mov cx,[r];@07<5@ <0A820 2 109BE 
aaa1: 
        cmp ax,bx 
                jb m1;<5=LH5 
                 
                 
                div bl 
                 
                 
                  
        jmp n2   
m1:              
        mov ah,al        
n2:              
        LODSB 
         
        loop aaa1 
                 
         
        cmp ah,0 
        jne mexit 
          
         
 mov ah,9 
 lea dx,msg 
 int 21h 
  
mexit: 
mov     ax,4c00h 
int     21h 
    

Replace mov cx, r with mov cx, [r] as pointed out by revolution.
Code:
end start 
    

No need for this crap.
Quote:
and that it was possible to write a number from the keyboard and output to the console

Well, you don't actually get a "number" from the keyboard it's an ASCII char (if you use the BIOS, or it's a scan code, then you need a lookup table.), a common example is:
Code:
;; Read Num - Read a number from keyboard, (E)DI - Pointer to buffer.
read_num:
;; Read a character from keyboard (for Real Mode)
xor cx, cx
.loop:
xor ax, ax ;--Null out ax.
int 0x16 ;--Cool. AL = ASCII Char, AH = Scan Code
;; print the number
call print_char ;; lazy to write this, but it should print the character to screen
;; with AL = char.
;; don't bother with scan code we need the ASCII char.
add al, 48 ; --- Convert to Decimal. may need to add a 'd' iirc.
;; stosb - store a character from AL to DS:(E)DI
stosb
;; is cx = 256 (max chars, change if you want to)
cmp cx, 256
je .done
inc cx
jmp .loop
.done:
....
    

-sid123

_________________
"Those who can make you believe in absurdities can make you commit atrocities" -- Voltaire https://github.com/Benderx2/R3X
XD


Last edited by sid123 on 09 Apr 2014, 13:40; edited 3 times in total
Post 09 Apr 2014, 12:30
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17274
Location: In your JS exploiting you and your system
revolution
Something to add is that the tasm code above was for an MZ (not a com) file. Hence the .data and .code sections. So we should add a "format mz" line in there and put in the explicit "section ..." lines for data and code.

Also, "mov cx,r" should be "mov cx,[r]".
Post 09 Apr 2014, 13:13
View user's profile Send private message Visit poster's website Reply with quote
sid123



Joined: 30 Jul 2013
Posts: 340
Location: Asia, Singapore
sid123
revolution wrote:
Something to add is that the tasm code above was for an MZ (not a com) file. Hence the .data and .code sections. So we should add a "format mz" line in there and put in the explicit "section ..." lines for data and code.

Also, "mov cx,r" should be "mov cx,[r]".

Right, I didn't notice that the value of CX was needed, I thought addresses were needed.
Post fixed.
Btw COM/MZ shouldn't make a difference for a small program like this, anyways point noted.

_________________
"Those who can make you believe in absurdities can make you commit atrocities" -- Voltaire https://github.com/Benderx2/R3X
XD
Post 09 Apr 2014, 13:38
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17274
Location: In your JS exploiting you and your system
revolution
sid123 wrote:
Right, I didn't notice that the value of CX was needed, I thought addresses were needed.
In MASM mode (TASMs default mode) both "mov reg,a" and "mov reg,[a]" are the same thing. That is why it needed the existence of "offset" to get the address and not the value. It was terrible and still is terrible. It was confusing and still is confusing. And sometimes I think that it was done deliberately to make assembly code look stupid so as to promote HLLs.

TASM also had an "ideal" mode which treated addresses in the same way as fasm does, and the keyword "offset" is then redundant.
Post 09 Apr 2014, 13:49
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.