Assembly Language New Line

16,498

Solution 1

CRLF is just a sequence of two bytes added to the output, the values 13 and 10.

If you made a string with those two values, perhaps prompt BYTE 'Hello!', 13, 10, 0 or just consisting of the cr/lf 13,10,0 combo, you can output it without a special procedure.

Solution 2

To expand upon adam's answer, this might be exactly what you are looking for:

carriageReturn BYTE ' ', 13, 10, 0

then call it as:

mov edx,OFFSET report1       ;Display sum result
call WriteString
call WriteInt
mov edx,OFFSET carriageReturn ; new line
call WriteString

That way the carriage return is after WriteInt

Share:
16,498
Moxy
Author by

Moxy

Computer Science Student and Video Game Enthusiast.

Updated on June 04, 2022

Comments

  • Moxy
    Moxy almost 2 years

    I'm brand new to assembly language programming, and I would like my output to have separate lines so that it is easier to read, however, I wrote my code and had it working, but was then informed that I could not in fact use the Irvine procedure to make a new line. My text book only uses the Irvine "Crlf" and the code from other people who asked similar questions on this website completely broke my program so now I'm lost.

    One I attempted was:

    mov ah, 0Eh       ;print new line sequence
    mov al, 0Dh
    int 10h
    mov al, 0Ah
    int 10h
    

    Anyways, here is my complete code with the Irvine function still. Can someone help me get the output I'm looking for without using the "call Crlf"? Or let me know why the code above is breaking my program? I'm sure there's something I'm missing.

    INCLUDE Irvine32.inc
    
    
    .data
    prompt BYTE 'Enter a positive integer: ', 0     
    report1 BYTE 'The sum is: ', 0              
    report2 BYTE 'The product is: ', 0
    report3 BYTE 'The power result is: ', 0
    temp DWORD ? ;
    .code
    
    main PROC
    ; Main program control procedure.
    ; Calls: GetInteger, AddNumbers, MultiplyNumbers,
    ;       WriteInt, CalculatePower
    
    call GetInteger             ;Get the first user entered integer
    mov ebx, eax                ;Store the value into the EBX register
    call GetInteger             ;Get the second user entered integer
    mov temp,eax                ;Copy the value into temp for holding
    call AddNumbers             ;Find the sum of the two integers
    mov edx,OFFSET report1      ;Display sum result
    call WriteString
    call WriteInt
    mov eax, temp               ;Replace the EAX value with the second user entered integer
    call MultiplyNumbers        ;Find the product of the two integers
    call Crlf                   ;New line
    mov edx,OFFSET report2      ;Display the product result
    call WriteString
    call WriteInt
    mov eax, temp               ;Replace the EAX value with the second user entered integer
    call CalculatePower         ;Find the power result of the two integers
    call Crlf                   ;New line
    mov edx,OFFSET report3      ;Display the power result
    call WriteString
    call WriteInt
        exit                    ;exit to operating system
    main ENDP
    
    ;-------------------------------------------------------------
    GetInteger PROC
    ;
    ; Prompts the user for two integers and stores 
    ; them into EAX and EBX registers
    ; Receives: Doubleword integers 
    ; Returns: The two integer values in the EAX and EBX registers
    ; Calls: WriteString, ReadInt
    ;----------------------------------------------------------------
        mov edx,OFFSET prompt   ;Prompt user for integer entry
        call WriteString
        call ReadInt
        ret
    GetInteger ENDP
    
    ;-----------------------------------------------------------------
    AddNumbers PROC
    ;
    ; Calculates the sum of two 32-bit integers
    ; Receives: The integer values in the registers EAX and EBX
    ; Returns: The sum in the EAX register
    ; Calls: none
    ;------------------------------------------------------------------
        add eax,ebx         ;Find the sum 
        ret
    AddNumbers ENDP
    
    ;--------------------------------------------------------------------
    MultiplyNumbers PROC
    ;
    ; Calculates the product of two 32-bit integers
    ; Receives: The integer values in the registers EAX and EBX 
    ; Returns: The product in the EAX register
    ; Calls: none
    ;---------------------------------------------------------------------
        mul ebx             ;Find the product
        ret 
    MultiplyNumbers ENDP
    
    ;--------------------------------------------------------------------
    CalculatePower PROC
    ;
    ; Calculates the result of the first 32 bit integer to the power
    ; of the second by using MultiplyNumbers
    ; Receives: The result of MultiplyNumbers
    ; Returns: The power result in EAX register
    ; Calls: MultiplyNumbers
    ;---------------------------------------------------------------------
        mov ecx,eax         ;Set the counter with the value of the second integer
        sub ecx, 1          ;Subtract one so the counter calls MultiplyNumbers the correct amount
        mov eax,ebx         ;Copy EBX into EAX so that MultiplyNumbers finds the power result
    
        FindPower:
            call MultiplyNumbers;Find the power result
            loop FindPower  ;Repeat the loop till the count is 0
    
        ret
    CalculatePower ENDP
    
    END main
    
  • Moxy
    Moxy almost 9 years
    Excellent! That's way easier than what I was trying to do. Thank you so much for the rapid response!
  • labyrinth
    labyrinth over 3 years
    Remember on *nix you leave out 13 and just use 10 for the newline.