hi all
currently i'm reading "X86 Assembly Language and C Fundamentals" by Joseph Cavanagh and i have some questions that i cant find its answer in the book
first the author focused on c inline assembly, he also showed how to write it in only assembly but he dosent tell how to compile or link these assembly programm, he doesnt even tell which assembler we should use
here is the syntax of the first programm
;swap_bytes.asm
;-----------------------------------------------------------
.STACK
;-----------------------------------------------------------
.DATA
TEMP
DB ?
;$ sign is a delimiter meaning end of string
RSLT
DB 0DH, 0AH, 'BL = , BH = $'
;-----------------------------------------------------------
.CODE
BEGIN
PROC FAR
;set up pgm ds
MOV
AX, @DATA
MOV
DS, AX
;place the .DATA addr in ax
;set up data seg addr for this pgm
;assign values to bl and bh
MOV
BL,'A'
MOV
BH, 'B'
;store bl in temp area before swapping
MOV
TEMP, BL
;swap registers
MOV
BL, BH
MOV
BH, TEMP
;move registers to result area for display
MOV
RSLT + 7, BL
MOV
RSLT + 15, BH
;print result
MOV
AH, 09H
;display string
MOV
DX, OFFSET RSLT ;rslt addr must be in dx
INT
21H
;a dos interrupt that uses
;a fctn code in ah
BEGIN ENDP
END
BEGIN
;start pgm at begin
and it equlivant C code
#include "stdafx.h"
char main (void)
{
char temp;
char rslt1, rslt2;
//switch to assembly
_asm
{
MOV
BL, 'A'
MOV
BH, 'B'
//swap bytes
MOV
temp, BL
MOV
rslt1, BH
MOV
BH, temp
MOV
rslt2, BH
}
//print result
printf ("BL = %c, BH = %c\n", rslt1, rslt2);
return 0;
}
which memory mode this asm program written for ? how do i compile and link with masm ?
This is 16 bit code.
;swap_bytes.asm
;-----------------------------------------------------------
.STACK
;-----------------------------------------------------------
.DATA
TEMP DB ?
RSLT DB 0DH, 0AH, 'BL = , BH = ',$ ;$ sign is a delimiter meaning end of string
;-----------------------------------------------------------
.CODE
BEGIN PROC FAR
MOV AX, @DATA ;set up pgm ds
MOV DS, AX ;place the .DATA addr in ax
;set up data seg addr for this pgm
MOV BL,'A' ;assign values to bl and bh
MOV BH, 'B'
MOV TEMP, BL ;store bl in temp area before swapping
MOV BL, BH ;swap registers
MOV BH, TEMP
MOV RSLT + 7, BL ;move registers to result area for display
MOV RSLT + 15, BH
MOV AH, 09H ;print result, display string
MOV DX, OFFSET RSLT ;rslt addr must be in dx
INT 21H ;a dos interrupt that uses
;a fctn code in ah
BEGIN ENDP
END BEGIN ;start pgm at begin
You can use masm and a 16 bit linker. And maybe try to run the program in a DosBox emulator program (DosBox). But i don't recall the exactly syntax for the assembler (command lines options for the assembler and the linker).
Btw, welcome to the forum. If you want you can start to learn 32 bit assembly language and in this great forum (with the masm32 sdk package) you will get a great time!
thanks felipe , i compiled and linked it with these command and it worked
ml /c /omf file.asm
link16 file.obj,,,,,
now i'm willing to convert it to 32-bit flat module and i have a question , what should i use instead of DOS system interrupts ?
Have a close look at Tips, Tricks and Traps (http://www.webalice.it/jj2006/Masm32_Tips_Tricks_and_Traps.htm).
ahmedES:
You can try with jj's proposal if you like. But related to this question:
Quote from: ahmedES on December 13, 2017, 03:19:36 PM
what should i use instead of DOS system interrupts ?
You have to decide for what operating system you want to produce code: DOS or Windows.
Once you know that, you can find a lot of ways for start doing just that, for example with jj's proposal if you choose Windows.
:t
it's likely a SMALL model program
which means a single code segment and a single data segment
common 16-bit models:
TINY - all code, data, and stack are in one segment
SMALL - one code segment, one data segment, one stack segment
MEDIUM - multiple code segments, one data segment, one stack segment
COMPACT - one code segment, multiple data segments, one stack segment
LARGE - multiple code segments, multiple data segments, one stack segment
HUGE - like LARGE, but a single array may be greater than 64 Kb
thank you guys , i understand now the difference between 16-bit assembly and 32-bit , and i decided to learn 32-bit assembly in windows platform
thank you again