This is actually my second question about this particular problem today, but the other one was answered pretty quickly.
In essence, I am trying to take in a string of letters (no numbers or symbols) and then compare each inputted letter to an array of .asciz
values that represent the NATO Military Phonetic Alphabet (Alpha, Bravo, Charlie, etc.) and output the representative Military equivalent to the letter.
This is where I am stuck. I'm fairly new to Assembly and this is a homework assignment, so help is much needed and appreciated. My professor is not great at offering resources to learn this stuff and it's difficult to find good resources for exact problems online.
Any help would be much appreciated. Specifically on how to compare each letter input to the array. I've already successfully stored the input in a variable.
Below is a C# representation of what I am attempting to do.
class MilAlpha
{
static void Main(string[] args)
{
string input;
string[] miliAlpha = { "Alpha", "Beta", "Charlie", "Delta", "Echo", "Foxtrot", "Golf",
"Hotel", "India", "Juliet", "Kilo", "Lima", "Mike", "November",
"Oscar", "Papa", "Quebec", "Romeo", "Sierra", "Tango", "Uniform",
"Victor", "Whiskey", "X-Ray", "Yankee", "Zulu" };
Console.WriteLine("Enter a string of text: ");
input = Console.ReadLine();
for (int i = 0; i < input.Length; i++) {
for (int j = 0; j < miliAlpha.Length; j++) {
if (input[i] == ' ')
Console.WriteLine("\n")
string temp = miliAlpha[j].ToLower();
if (input[i] == temp[0])
Console.WriteLine("\n" + miliAlpha[j] + "\n");
}
}
Console.ReadKey();
}
}
EDIT:
So I believe this should do what I am trying to do, but it doesn't seem to work as intended. It compares the correct things in the debugger, but when it goes to print the respective portion of the array, it simply doesn't print anything.
.section .data
MAlpha:
.asciz "Alpha \n"
.equ ElementLen, .-MAlpha
.asciz "Bravo \n"
.asciz "Charlie \n"
.asciz "Delta \n"
.asciz "Echo \n"
.asciz "Foxtrot \n"
.asciz "Golf \n"
.asciz "Hotel \n"
.asciz "India \n"
.asciz "Juliet \n"
.asciz "Kilo \n"
.asciz "Lima \n"
.asciz "Mike \n"
.asciz "November \n"
.asciz "Oscar \n"
.asciz "Papa \n"
.asciz "Quebec \n"
.asciz "Romeo \n"
.asciz "Sierra \n"
.asciz "Tango \n"
.asciz "Uniform \n"
.asciz "Victor \n"
.asciz "Whiskey \n"
.asciz "X-Ray \n"
.asciz "Yankee \n"
.asciz "Zulu \n"
.asciz " \n"
.equ MAlphaLen, .-MAlpha
Input:
.fill 80
.equ InputLen, .-Input
InputMSG:
.ascii "Please enter a word: "
.equ InputMSGLen, .-InputMSG
BlankLine:
.ascii "\n"
.equ BlankLineLen, .-BlankLine
Converting:
.ascii "\nConverting to NATO Alphabet...\n\n"
.equ ConvertingLen, .-Converting
.section .bss
.section .text
.globl _start
GetInput:
movl $4, %eax
movl $1, %ebx
movl $InputMSG, %ecx
movl $InputMSGLen, %edx
int $0x80
movl $3, %eax
movl $0, %ebx
movl $Input, %ecx
movl $InputLen, %edx
int $0x80
ret
PrintInput:
movl $4, %eax
movl $1, %ebx
movl $BlankLine, %ecx
movl $BlankLineLen, %edx
int $0x80
movl $4, %eax
movl $1, %ebx
movl $Input, %ecx
movl $InputLen, %edx
int $0x80
movl $4, %eax
movl $1, %ebx
movl $Converting, %ecx
movl $ConvertingLen, %edx
int $0x80
ret
Convert:
# Get first letter of input string
# Compare letter to first letter of each array entry
# When match is found, print Array entry to screen
# Repeat until end of input string
movl $Input, %eax
movl $MAlpha, %edi
call Loop
ret
Loop:
movb (%eax), %al
cmp $0x0A, %al
je Finished
call CompareAlpha
jmp Loop
CompareAlpha:
movb (%edi), %bl
cmpb %bl, %al
je PrintWord
addl $ElementLen, %edi
jmp CompareAlpha
PrintWord:
movl $4, %eax
movl $1, %ebx
movl (%edi), %eax
movl $ElementLen, %edx
int $0x80
Finished:
call ExitProg
_start:
call GetInput
call PrintInput
call Convert
call ExitProg
PrintMAlpha:
movl $4, %eax
movl $1, %ebx
movl $MAlpha, %ecx
movl $MAlphaLen, %edx
int $0x80
ExitProg:
movl $1, %eax
movl $0, %ebx
int $0x80